From b769af245981536f49f14a3c959a55f9726d12e3 Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 17 May 2015 03:20:28 +0100 Subject: [PATCH] More work on alerting config --- html/forms/update-config-item.inc.php | 42 +++++++++++ html/images/pd_connect_button.png | Bin 0 -> 2993 bytes html/includes/functions.inc.php | 31 ++++++++ html/pages/settings.inc.php | 14 +++- html/pages/settings/alerting.inc.php | 105 ++++++++++++++++++++++++-- sql-schema/051.sql | 3 +- 6 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 html/forms/update-config-item.inc.php create mode 100644 html/images/pd_connect_button.png diff --git a/html/forms/update-config-item.inc.php b/html/forms/update-config-item.inc.php new file mode 100644 index 000000000..1671d2f27 --- /dev/null +++ b/html/forms/update-config-item.inc.php @@ -0,0 +1,42 @@ + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +$status = 'error'; + +if (!is_numeric($_POST['config_id'])) { + $message = 'ERROR: No alert selected'; + exit; +} else { + if($_POST['config_value'] === true) { + $state = TRUE; + } else { + $state = FALSE; + } + $state = $_POST['config_value']; + $update = dbUpdate(array('config_value' => $state), 'config', '`config_id`=?', array($_POST['config_id'])); + if(!empty($update) || $update == '0') + { + $message = 'Alert rule has been updated.'; + $status = 'ok'; + } else { + $message = 'ERROR: Alert rule has not been updated.'; + } +} + +$response = array('status'=>$status,'message'=>$message); +echo _json_encode($response); \ No newline at end of file diff --git a/html/images/pd_connect_button.png b/html/images/pd_connect_button.png new file mode 100644 index 0000000000000000000000000000000000000000..a03220b8359de235cfe231aa22c8ed3d210de704 GIT binary patch literal 2993 zcmV;i3r_TjP)+9<&iy3OcYbK8!;qBmEs#&wl zv5LWmySuw3ogzf6KPi?Se8qbwrzAC>F1FpZZL?{4d3h$39vo{Gdb4&kkt*=@@LZ-? zN{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{<4#iP_@3=TR^G54rQ;j6%MnrQw{KaE((x^u<=a-#mPg*U8l~gg zHp?ShL=(Pv$7+<0@7OF~Ob~rJ=CfzswGyS{yEe)*pN;uabYaw(&mXoD<-@kh=VL~_ nAi{-FU$-9lKd1HUQ5W!UJaKf@#WYQj00000NkvXXu0mjfagV7? literal 0 HcmV?d00001 diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 9c37be97b..2a86aa055 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -786,4 +786,35 @@ function add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf return($db_inserted); } +function get_config_by_group($group) { + $group = array($group); + foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_group` = '?'", array($group)) as $config_item) { + $items[] = $config_item; + } + return $items; +} + +function get_config_by_name($name) { + $name = array($name); + foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_name` = '?'", array($name)) as $config_item) { + $items[] = $config_item; + } + return $items; +} + +function set_config_name($name,$config_value) { + return dbUpdate(array('config_value' => $config_value), 'config', '`config_name`=?', array($name)); +} + +function get_url() { + // http://stackoverflow.com/questions/2820723/how-to-get-base-url-with-php + // http://stackoverflow.com/users/184600/ma%C4%8Dek + return sprintf( + "%s://%s%s", + isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', + $_SERVER['SERVER_NAME'], + $_SERVER['REQUEST_URI'] + ); +} + ?> diff --git a/html/pages/settings.inc.php b/html/pages/settings.inc.php index 85c69e96e..3dac71da6 100644 --- a/html/pages/settings.inc.php +++ b/html/pages/settings.inc.php @@ -23,9 +23,21 @@ * @subpackage Page */ +?> + +
+
+
+ +
+
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ Connect to PagerDuty +
+
+
+
+
+ +'; + ?> -
-
-
'); + } else { + $("#message").html('
' + data.message + '
'); + } + }, + error: function () { + $("#message").html('
An error occurred.
'); + } + }); + }); + diff --git a/sql-schema/051.sql b/sql-schema/051.sql index 55ee4adfc..6538df71f 100644 --- a/sql-schema/051.sql +++ b/sql-schema/051.sql @@ -1 +1,2 @@ -CREATE TABLE `config` ( `config_id` int(11) NOT NULL AUTO_INCREMENT, `config_name` varchar(255) NOT NULL, `config_value` varchar(255) NOT NULL, `config_default` varchar(255) NOT NULL, `config_type` enum('array','single','multi-array','single-array') NOT NULL DEFAULT 'single', `config_desc` varchar(100) NOT NULL, `config_group` varchar(50) NOT NULL, `config_sub_group` varchar(50) NOT NULL, `config_hidden` enum('0','1') NOT NULL DEFAULT '0', `config_disabled` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`config_id`) ) ENGINE=InnoDB AUTO_INCREMENT=437 DEFAULT CHARSET=latin1; +CREATE TABLE `config` ( `config_id` int(11) NOT NULL AUTO_INCREMENT, `config_name` varchar(255) NOT NULL, `config_value` varchar(512) NOT NULL, `config_default` varchar(512) NOT NULL, `config_type` enum('array','single','multi-array','single-array') NOT NULL DEFAULT 'single', `config_desc` varchar(100) NOT NULL, `config_form` text NOT NULL, `config_group` varchar(50) NOT NULL, `config_group_order` int(11) NOT NULL, `config_sub_group` varchar(50) NOT NULL, `config_sub_group_order` int(11) NOT NULL, `config_hidden` enum('0','1') NOT NULL DEFAULT '0', `config_disabled` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`config_id`) ENGINE=InnoDB AUTO_INCREMENT=428 DEFAULT CHARSET=latin1; +INSERT INTO `config` VALUES (405,'alert,macros,rule,now','NOW()','NOW()','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(406,'alert,macros,rule,past_5m','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(407,'alert,macros,rule,past_10m','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(408,'alert,macros,rule,past_15m','DATE_SUB(NOW(),INTERVAL 15 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(409,'alert,macros,rule,past_30m','DATE_SUB(NOW(),INTERVAL 30 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(410,'alert,macros,rule,past_60m','DATE_SUB(NOW(),INTERVAL 60 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','single-array','Time macro','text:','alerting',100,'macros',10,'0','0'),(411,'alert,macros,rule,device','(%devices.disabled = \"0\" && %devices.ignore = \"0\")','(%devices.disabled = \"0\" && %devices.ignore = \"0\")','single-array','Device macro','text:','alerting',100,'macros',10,'0','0'),(412,'alert,macros,rule,device_up','(%devices.status = \"1\" && %macros.device)','(%devices.status = \"1\" && %macros.device)','single-array','Device macro','text:','alerting',100,'macros',10,'0','0'),(413,'alert,macros,rule,device_down','(%devices.status = \"0\" && %macros.device)','(%devices.status = \"0\" && %macros.device)','single-array','Device macro','text:','alerting',100,'macros',10,'0','0'),(414,'alert,macros,rule,port','(%ports.deleted = \\\"0\\\" && %ports.ignore = \\\"0\\\" && %ports.disabled = \\\"0\\\")','(%ports.deleted = \"0\" && %ports.ignore = \"0\" && %ports.disabled = \"0\")','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(415,'alert,macros,rule,port_up','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(416,'alert,macros,rule,port_down','(%ports.ifOperStatus = \\\"down\\\" && %ports.ifAdminStatus != \\\"down\\\" && %macros.port)','(%ports.ifOperStatus = \"down\" && %ports.ifAdminStatus != \"down\" && %macros.port)','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(417,'alert,macros,rule,port_usage_perc','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','single-array','Port macro','text:','alerting',100,'macros',10,'0','0'),(418,'alert,transports,dummy','false','false','single-array','Transports','radio:false,true','alerting',100,'transports',8,'0','0'),(419,'alert,transports,mail','false','false','single-array','Transports','radio:false,true','alerting',100,'transports',8,'0','0'),(420,'alert,transports,irc','false','false','single-array','Transports','radio:false,true','alerting',100,'transports',8,'0','0'),(421,'alert,globals','false','false','single-array','Issue alerts to global-read users','radio:false,true','alerting',100,'global',5,'0','0'),(422,'alert,admins','true','false','single-array','Issue alerts to admins','radio:false,true','alerting',100,'global',5,'0','0'),(423,'alert,default_only','true','false','single-array','Alert settings','radio:false,true','alerting',100,'global',5,'0','0'),(424,'alert,default_mail','','','single-array','Alert settings','text:','alerting',100,'global',5,'0','0'),(425,'alert,transports,pagerduty','false','false','single-array','Pagerduty transport','','alerting',100,'transports',8,'0','0'),(426,'alert,pagerduty,account','false','false','single-array','Pagerduty account name','','alerting',100,'transports',8,'0','0'),(427,'alert,pagerduty,service','false','false','single-array','Pagerduty service name','','alerting',100,'transports',8,'0','0');