From 8327466d14e09b01e9d7540e4b85fbc8c8eb17f5 Mon Sep 17 00:00:00 2001 From: laf Date: Fri, 15 May 2015 14:19:45 +0100 Subject: [PATCH] Adding alerting config --- html/pages/settings.inc.php | 64 +++++++++++++++++++++++++++--------- includes/defaults.inc.php | 38 --------------------- includes/definitions.inc.php | 8 ++--- sql-schema/051.sql | 1 + 4 files changed, 54 insertions(+), 57 deletions(-) create mode 100644 sql-schema/051.sql diff --git a/html/pages/settings.inc.php b/html/pages/settings.inc.php index 584d3d87f..1b38e87cf 100644 --- a/html/pages/settings.inc.php +++ b/html/pages/settings.inc.php @@ -1,17 +1,50 @@ - * - * 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. +/* Copyright (C) 2015 Daniel Preussker + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +/** + * Global Settings + * @author f0o + * @copyright 2015 f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Page */ +/** + * Array-To-Table + * @param array $a N-Dimensional, Associative Array + * @return string + */ + +function a2t($a) { + $r = ""; + foreach( $a as $k=>$v ) { + if( !empty($v) ) { + $r .= ""; + } + } + $r .= '
".$k."".(is_array($v)?a2t($v):"".wordwrap($v,75,"
")."
")."
'; + return $r; +} +if( $_SESSION['userlevel'] >= 10 ) { + echo "
".a2t($config)."
"; +} else { + include("includes/error-no-perm.inc.php"); +} + if ($_SESSION['userlevel'] >= '10') { ?> @@ -101,9 +134,10 @@ $('#multi_value').toggle();
'); - foreach (dbFetchRows("SELECT config_id,config_group FROM `config` WHERE config_hidden='0' GROUP BY config_group ORDER BY config_group ASC") as $group) + foreach (dbFetchRows("SELECT config_id,config_group FROM `config` WHERE config_hidden='0' GROUP BY config_group ORDER BY config_group ASC ,config_group_order DESC") as $group) { - list($grp_num,$grp_title) = explode("_",$group['config_group']); + $grp_num = $group['config_group_order']; + $grp_title = $group['config_group']; $found++; echo('
@@ -117,7 +151,7 @@ $('#multi_value').toggle();
'); - foreach (dbFetchRows("SELECT * FROM `config` WHERE config_group='".$group['config_group']."' ORDER BY config_sub_group ASC, config_name ASC") as $cfg) + foreach (dbFetchRows("SELECT * FROM `config` WHERE config_group='".$group['config_group']."' ORDER BY config_sub_group ASC, config_sub_group_order DESC, config_name ASC") as $cfg) { $cfg_ids[] = $cfg['config_id']; $cfg_disabled = ''; @@ -127,9 +161,9 @@ $('#multi_value').toggle(); } echo('
- +
- +
diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index b8943412f..62b67b5f4 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -201,44 +201,6 @@ $config['email_smtp_auth'] = FALSE; // Whether or not $config['email_smtp_username'] = NULL; // SMTP username. $config['email_smtp_password'] = NULL; // Password for SMTP authentication. -// Alerting Settings - -$config['alert'] = array( - 'macros' => array( //Macros: - 'rule' => array( // For Rules - //Time Macros - 'now' => 'NOW()', - 'past_5m' => 'DATE_SUB(NOW(),INTERVAL 5 MINUTE)', - 'past_10m' => 'DATE_SUB(NOW(),INTERVAL 10 MINUTE)', - 'past_15m' => 'DATE_SUB(NOW(),INTERVAL 15 MINUTE)', - 'past_30m' => 'DATE_SUB(NOW(),INTERVAL 30 MINUTE)', - 'past_60m' => 'DATE_SUB(NOW(),INTERVAL 60 MINUTE)', - - //Device Macros - 'device' => '(%devices.disabled = "0" && %devices.ignore = "0")', - 'device_up' => '(%devices.status = "1" && %macros.device)', - 'device_down' => '(%devices.status = "0" && %macros.device)', - - //Port Macros - 'port' => '(%ports.deleted = "0" && %ports.ignore = "0" && %ports.disabled = "0")', - 'port_up' => '(%ports.ifOperStatus = "up" && %ports.ifAdminStatus = "up" && %macros.port)', - 'port_down' => '(%ports.ifOperStatus = "down" && %ports.ifAdminStatus != "down" && %macros.port)', - 'port_usage_perc' => '((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100', - - //Misc Macros - ), - ), - 'transports' => array( //Transports: - 'dummy' => false, // Dummy alerting (debug) - 'mail' => false, // E-Mail alerting - 'irc' => false, // IRC Alerting - ), - 'globals' => false, //Issue to global-read users - 'admins' => false, //Issue to administrators - 'default_only' => false, //Only issue to default - 'default_mail' => '', //Default email -); - //Legacy options $config['alerts']['email']['default'] = NULL; // Default alert recipient diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 28e66069f..564697dfe 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -58,7 +58,7 @@ foreach ($single_config as $config_data) $tmp_name = $config_data['config_name']; if(!isset($config[$tmp_name])) { - $config[$tmp_name] = $config_data['config_value']; + $config[$tmp_name] = stripslashes($config_data['config_value']); } } // Array config values @@ -69,7 +69,7 @@ foreach ($array_config as $config_data) $tmp_name = $config_data['config_name']; if(!isset($config[$tmp_name])) { - $config[$tmp_name] = explode(',',$config_data['config_value']); + $config[$tmp_name] = explode(',',stripslashes($config_data['config_value'])); } } @@ -78,7 +78,7 @@ $config_vars = get_defined_vars(); $multi_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'multi-array' AND `config_disabled` = '0' GROUP BY config_name"); foreach ($multi_array_config as $config_data) { - create_array($config,$config_data['config_name'],$config_data['config_value'],'multi'); + create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'multi'); } // Single-array config values @@ -86,7 +86,7 @@ $config_vars = get_defined_vars(); $single_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'single-array' AND `config_disabled` = '0' GROUP BY config_name"); foreach ($single_array_config as $config_data) { - create_array($config,$config_data['config_name'],$config_data['config_value'],'single'); + create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'single'); } unset($config_vars); diff --git a/sql-schema/051.sql b/sql-schema/051.sql new file mode 100644 index 000000000..55ee4adfc --- /dev/null +++ b/sql-schema/051.sql @@ -0,0 +1 @@ +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;