Adding alerting config

This commit is contained in:
laf
2015-05-15 14:19:45 +01:00
parent d315014c96
commit 8327466d14
4 changed files with 54 additions and 57 deletions

View File

@@ -1,17 +1,50 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
*
* 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 <f0o@devilcode.org>
* 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 <http://www.gnu.org/licenses/>. */
/**
* Global Settings
* @author f0o <f0o@devilcode.org>
* @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 = "<table class='table table-condensed table-hover'><tbody>";
foreach( $a as $k=>$v ) {
if( !empty($v) ) {
$r .= "<tr><td class='col-md-2'><i><b>".$k."</b></i></td><td class='col-md-10'>".(is_array($v)?a2t($v):"<code>".wordwrap($v,75,"<br/>")."</code>")."</td></tr>";
}
}
$r .= '</tbody></table>';
return $r;
}
if( $_SESSION['userlevel'] >= 10 ) {
echo "<div class='table-responsive'>".a2t($config)."</div>";
} else {
include("includes/error-no-perm.inc.php");
}
if ($_SESSION['userlevel'] >= '10') {
?>
@@ -101,9 +134,10 @@ $('#multi_value').toggle();
<div class="panel-group" id="accordion">
');
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('
<div class="panel panel-default">
@@ -117,7 +151,7 @@ $('#multi_value').toggle();
<div id="'.$grp_num.'_expand" class="panel-collapse collapse">
<div class="panel-body">
');
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('
<div class="form-group">
<label for="'.$cfg['config_id'].'" class="col-sm-3">'.$cfg['config_name'].': </label>
<label for="'.$cfg['config_id'].'" class="col-sm-3">$config[\''.str_replace(",", "']['", $cfg['config_name']).'\'] = </label>
<div class="col-sm-6 config-response">
<input type="input" class="form-control input-sm config-item" name="'.$cfg['config_id'].'" id="'.$cfg['config_id'].'" value="'.$cfg['config_value'].'">
<input type="input" class="form-control input-sm config-item" name="'.$cfg['config_id'].'" id="'.$cfg['config_id'].'" value="'.stripslashes(htmlspecialchars($cfg['config_value'])).'">
</div>
<div class="col-sm-1">
<div data-toggle="tooltip" title="'.$cfg['config_desc'].'" class="toolTip glyphicon glyphicon-question-sign"></div>

View File

@@ -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

View File

@@ -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);

1
sql-schema/051.sql Normal file
View File

@@ -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;