diff --git a/alerts.php b/alerts.php index 458fc330ab..fe27ea604b 100755 --- a/alerts.php +++ b/alerts.php @@ -247,7 +247,7 @@ function ExtTransports($obj) { global $config; $tmp = false; //To keep scrutinizer from naging because it doesnt understand eval foreach( $config['alert']['transports'] as $transport=>$opts ) { - if( ($opts === true || !empty($opts)) && file_exists($config['install_dir']."/includes/alerts/transport.".$transport.".php") ) { + if( ($opts === true || !empty($opts)) && $opts != false && file_exists($config['install_dir']."/includes/alerts/transport.".$transport.".php") ) { echo $transport." => "; eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir']."/includes/alerts/transport.".$transport.".php").' };'); $tmp = $tmp($obj,$opts); diff --git a/doc/Extensions/Alerting.md b/doc/Extensions/Alerting.md index a542be682d..f763f32b35 100644 --- a/doc/Extensions/Alerting.md +++ b/doc/Extensions/Alerting.md @@ -139,6 +139,8 @@ $config['alert']['admins'] = true; //Include Adminstrators into alert-contacts ## E-Mail +> You can configure these options within the WebUI now, please avoid setting these options within config.php + E-Mail transport is enabled with adding the following to your `config.php`: ```php $config['alert']['transports']['mail'] = true; @@ -165,6 +167,8 @@ $config['alert']['default_mail'] = ''; //Default ema ## API +> You can configure these options within the WebUI now, please avoid setting these options within config.php + API transports definitions are a bit more complex than the E-Mail configuration. The basis for configuration is `$config['alert']['transports']['api'][METHOD]` where `METHOD` can be `get`,`post` or `put`. This basis has to contain an array with URLs of each API to call. @@ -180,6 +184,8 @@ $config['alert']['transports']['api']['get'][] = "https://api.thirdparti.es/issu ## Nagios Compatible +> You can configure these options within the WebUI now, please avoid setting these options within config.php + The nagios transport will feed a FIFO at the defined location with the same format that nagios would. This allows you to use other Alerting-Systems to work with LibreNMS, for example [Flapjack](http://flapjack.io). ```php @@ -188,6 +194,8 @@ $config['alert']['transports']['nagios'] = "/path/to/my.fifo"; //Flapjack expect ## IRC +> You can configure these options within the WebUI now, please avoid setting these options within config.php + The IRC transports only works together with the LibreNMS IRC-Bot. Configuration of the LibreNMS IRC-Bot is described [here](https://github.com/librenms/librenms/blob/master/doc/Extensions/IRC-Bot.md). ```php @@ -196,6 +204,8 @@ $config['alert']['transports']['irc'] = true; ## Slack +> You can configure these options within the WebUI now, please avoid setting these options within config.php + The Slack transport will POST the alert message to your Slack Incoming WebHook, you are able to specify multiple webhooks along with the relevant options to go with it. All options are optional, the only required value is for url, without this then no call to Slack will be made. Below is an example of how to send alerts to two channels with different customised options: ```php @@ -207,6 +217,8 @@ $config['alert']['transports']['slack'][] = array('url' => "https://hooks.slack. ## HipChat +> You can configure these options within the WebUI now, please avoid setting these options within config.php + The HipChat transport requires the following: __room_id__ = HipChat Room ID @@ -252,6 +264,8 @@ $config['alert']['transports']['hipchat'][] = array("url" => "https://api.hipcha ## PagerDuty +> You can configure these options within the WebUI now, please avoid setting these options within config.php + Enabling PagerDuty transports is almost as easy as enabling email-transports. All you need is to create a Service with type Generic API on your PagerDuty dashboard. diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index 99d0eac664..9d6095859c 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -215,6 +215,8 @@ Arrays of subnets to exclude in auto discovery mode. #### Email configuration +> You can configure these options within the WebUI now, please avoid setting these options within config.php + ```php $config['email_backend'] = 'mail'; $config['email_from'] = NULL; diff --git a/html/form_new_config.php b/html/form_new_config.php new file mode 100644 index 0000000000..6f45a3d6c4 --- /dev/null +++ b/html/form_new_config.php @@ -0,0 +1,99 @@ + + * + * 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. + */ + +enable_debug(); + +include_once("../includes/defaults.inc.php"); +include_once("../config.php"); +include_once("../includes/definitions.inc.php"); +include_once("includes/functions.inc.php"); +include_once("../includes/functions.php"); +include_once("includes/authenticate.inc.php"); + +if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } + +$new_conf_type = $_POST['new_conf_type']; +$new_conf_name = $_POST['new_conf_name']; +$new_conf_desc = $_POST['new_conf_desc']; + +if(empty($new_conf_name)) +{ + echo("You haven't specified a config name"); + exit; +} +elseif(empty($new_conf_desc)) +{ + echo("You haven't specified a config description"); + exit; +} +elseif(empty($_POST['new_conf_single_value']) && empty($_POST['new_conf_multi_value'])) +{ + echo("You haven't specified a config value"); + exit; +} + +$db_inserted = '0'; + +if($new_conf_type == 'Single') +{ + $new_conf_type = 'single'; + $new_conf_value = $_POST['new_conf_single_value']; + $db_inserted = add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc); +} +elseif($new_conf_type == 'Single Array') +{ + $new_conf_type = 'single-array'; + $new_conf_value = $_POST['new_conf_single_value']; + $db_inserted = add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc); +} +elseif($new_conf_type == 'Standard Array' || $new_conf_type == 'Multi Array') +{ + if($new_conf_type == 'Standard Array') + { + $new_conf_type = 'array'; + } + elseif($new_conf_type == 'Multi Array') + { + $new_conf_type = 'multi-array'; + } + else + { + # $new_conf_type is invalid so clear values so we don't create any config + $new_conf_value = ''; + } + $new_conf_value = nl2br($_POST['new_conf_multi_value']); + $values = explode('
',$new_conf_value); + foreach ($values as $item) + { + $new_conf_value = trim($item); + $db_inserted = add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc); + } +} +else +{ + echo('Bad config type!'); + $db_inserted = 0; + exit; +} + +if($db_inserted == 1) +{ + echo('Your new config item has been added'); +} +else +{ + echo('An error occurred adding your config item to the database'); +} + +?> diff --git a/html/forms/config-item-disable.inc.php b/html/forms/config-item-disable.inc.php new file mode 100644 index 0000000000..e44f6afdc0 --- /dev/null +++ b/html/forms/config-item-disable.inc.php @@ -0,0 +1,48 @@ + + * + * 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. + */ + +// FUA + +if(!is_numeric($_POST['config_id'])) +{ + echo('error with data'); + exit; +} +else +{ + if($_POST['state'] == 'true') + { + $state = 1; + } + elseif($_POST['state'] == 'false') + { + $state = 0; + } + else + { + $state = 0; + } + $update = dbUpdate(array('config_disabled' => $state), 'config', '`config_id` = ?', array($_POST['config_id'])); + if(!empty($update) || $update == '0') + { + echo('success'); + exit; + } + else + { + echo('error'); + exit; + } +} + diff --git a/html/forms/config-item-update.inc.php b/html/forms/config-item-update.inc.php new file mode 100644 index 0000000000..9ba7957861 --- /dev/null +++ b/html/forms/config-item-update.inc.php @@ -0,0 +1,37 @@ + + * + * 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. + */ + +// FUA + +if(!is_numeric($_POST['config_id']) || empty($_POST['data'])) +{ + echo('error with data'); + exit; +} +else +{ + $data = mres($_POST['data']); + $update = dbUpdate(array('config_value' => "$data"), 'config', '`config_id` = ?', array($_POST['config_id'])); + if(!empty($update) || $update == '0') + { + echo('success'); + exit; + } + else + { + echo('error'); + exit; + } +} + diff --git a/html/forms/config-item.inc.php b/html/forms/config-item.inc.php new file mode 100644 index 0000000000..1a481b64a3 --- /dev/null +++ b/html/forms/config-item.inc.php @@ -0,0 +1,108 @@ + + * + * 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) { + $response = array('status'=>'error','message'=>'Need to be admin'); + echo _json_encode($response); + exit; +} + +$action = mres($_POST['action']); +$config_group = mres($_POST['config_group']); +$config_sub_group = mres($_POST['config_sub_group']); +$config_name = mres($_POST['config_name']); +$config_value = mres($_POST['config_value']); +$config_extra = mres($_POST['config_extra']); +$config_room_id = mres($_POST['config_room_id']); +$config_from = mres($_POST['config_from']); +$status = 'error'; +$message = 'Error with config'; + +if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat') { + $config_id = mres($_POST['config_id']); + if (empty($config_id)) { + $message = 'No config id passed'; + } else { + if (dbDelete('config', '`config_id`=?', array($config_id))) { + if ($action == 'remove-slack') { + dbDelete('config', "`config_name` LIKE 'alert.transports.slack.$config_id.%'"); + } elseif ($action == 'remove-hipchat') { + dbDelete('config', "`config_name` LIKE 'alert.transports.hipchat.$config_id.%'"); + } + $status = 'ok'; + $message = 'Config item removed'; + } else { + $message = 'General error, could not remove config'; + } + } +} elseif ($action == 'add-slack') { + if (empty($config_value)) { + $message = 'No Slack url provided'; + } else { + $config_id = dbInsert(array('config_name' => 'alert.transports.slack.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'Slack Transport'), 'config'); + if ($config_id > 0) { + dbUpdate(array('config_name' => 'alert.transports.slack.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id)); + $status = 'ok'; + $message = 'Config item created'; + $extras = explode('\n',$config_extra); + foreach ($extras as $option) { + list($k,$v) = explode("=", $option,2); + if (!empty($k) || !empty($v)) { + dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$v, 'config_descr'=>'Slack Transport'), 'config'); + } + } + } else { + $message = 'Could not create config item'; + } + } +} elseif ($action == 'add-hipchat') { + if (empty($config_value) || empty($config_room_id) || empty($config_from)) { + $message = 'No hipchat url, room id or from provided'; + } else { + $config_id = dbInsert(array('config_name' => 'alert.transports.hipchat.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'Hipchat Transport'), 'config'); + if ($config_id > 0) { + dbUpdate(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id)); + dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.room_id', 'config_value' => $config_room_id, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_room_id, 'config_descr'=>'Hipchat URL'), 'config'); + dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.from', 'config_value' => $config_from, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_from, 'config_descr'=>'Hipchat From'), 'config'); + $status = 'ok'; + $message = 'Config item created'; + $extras = explode('\n',$config_extra); + foreach ($extras as $option) { + list($k,$v) = explode("=", $option,2); + if (!empty($k) || !empty($v)) { + dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$v, 'config_descr'=>'Hipchat '.$v), 'config'); + } + } + } else { + $message = 'Could not create config item'; + } + } +} else { + + if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) { + $message = 'Missing config name or value'; + } else { + $config_id = dbInsert(array('config_name' => $config_name, 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'API Transport'), 'config'); + if ($config_id > 0) { + dbUpdate(array('config_name'=>$config_name.$config_id),'config','config_id=?',array($config_id)); + $status = 'ok'; + $message = 'Config item created'; + } else { + $message = 'Could not create config item'; + } + } +} + +$response = array('status'=>$status,'message'=>$message, 'config_id'=>$config_id); +echo _json_encode($response); diff --git a/html/forms/update-config-item.inc.php b/html/forms/update-config-item.inc.php new file mode 100644 index 0000000000..4c8cc5545f --- /dev/null +++ b/html/forms/update-config-item.inc.php @@ -0,0 +1,62 @@ + + * + * 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'); +} + +$config_id = mres($_POST['config_id']); +$action = mres($_POST['action']); +$config_type = mres($_POST['config_type']); + +$status = 'error'; + +if (!is_numeric($config_id)) { + $message = 'ERROR: No alert selected'; +} elseif ($action == 'update-textarea') { + $extras = explode(PHP_EOL,$_POST['config_value']); + foreach ($extras as $option) { + list($k,$v) = explode("=", $option,2); + if (!empty($k) || !empty($v)) { + if ($config_type == 'slack') { + $db_id[] = dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default'=>$v, 'config_descr'=>'Slack Transport'), 'config'); + } elseif ($config_type == 'hipchat') { + $db_id[] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default'=>$v, 'config_descr'=>'Hipchat Transport'), 'config'); + } + } + } + $db_inserts = implode(",",$db_id); + if (!empty($db_inserts)) { + if ($config_type == 'slack') { + dbDelete('config',"(`config_name` LIKE 'alert.transports.slack.$config_id.%' AND `config_name` != 'alert.transports.slack.$config_id.url' AND `config_id` NOT IN ($db_inserts))"); + } elseif ($config_type == 'hipchat') { + dbDelete('config',"(`config_name` LIKE 'alert.transports.hipchat.$config_id.%' AND (`config_name` != 'alert.transports.hipchat.$config_id.url' AND `config_name` != 'alert.transports.hipchat.$config_id.room_id' AND `config_name` != 'alert.transports.hipchat.$config_id.from') AND `config_id` NOT IN ($db_inserts))"); + } + } + $message = 'Config item has been updated:'; + $status = 'ok'; +} else { + $state = mres($_POST['config_value']); + $update = dbUpdate(array('config_value' => $state), 'config', '`config_id`=?', array($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); diff --git a/html/images/pd_connect_button.png b/html/images/pd_connect_button.png new file mode 100644 index 0000000000..a03220b835 Binary files /dev/null and b/html/images/pd_connect_button.png differ diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 68324611cf..d7fe5b3232 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -774,7 +774,65 @@ function clean_bootgrid($string) { $output = str_replace(array("\r","\n"), "", $string); $output = addslashes($output); return $output; +} +//Insert new config items +function add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc) { + if (dbInsert(array('config_name' => $new_conf_name, 'config_value' => $new_conf_value, 'config_default' => $new_conf_value, 'config_type' => $new_conf_type, 'config_desc' => $new_conf_desc, 'config_group' => '500_Custom Settings', 'config_sub_group' => '01_Custom settings', 'config_hidden' => '0', 'config_disabled' => '0'), 'config')) { + $db_inserted = 1; + } else { + $db_inserted = 0; + } + return($db_inserted); +} + +function get_config_by_group($group) { + $group = array($group); + $items = array(); + foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_group` = '?'", array($group)) as $config_item) { + $val = $config_item['config_value']; + if (filter_var($val,FILTER_VALIDATE_INT)) { + $val = (int) $val; + } elseif (filter_var($val,FILTER_VALIDATE_FLOAT)) { + $val = (float) $val; + } elseif (filter_var($val,FILTER_VALIDATE_BOOLEAN)) { + $val =(boolean) $val; + } + if ($val === TRUE) { + $config_item += array('config_checked'=>'checked'); + } + $items[$config_item['config_name']] = $config_item; + } + return $items; +} + +function get_config_like_name($name) { + $name = array($name); + $items = array(); + foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_name` LIKE '%?%'", array($name)) as $config_item) { + $items[$config_item['config_name']] = $config_item; + } + return $items; +} + +function get_config_by_name($name) { + $config_item = dbFetchRow("SELECT * FROM `config` WHERE `config_name` = ?", array($name)); + return $config_item; +} + +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'] + ); } function alert_details($details) { diff --git a/html/pages/device/health/mempool.inc.php b/html/pages/device/health/mempool.inc.php index 2b4e5fcc82..6630c31476 100644 --- a/html/pages/device/health/mempool.inc.php +++ b/html/pages/device/health/mempool.inc.php @@ -13,7 +13,7 @@ foreach (dbFetchRows("SELECT * FROM `mempools` WHERE device_id = ?", array($devi { if (!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); if($debug) { print_r($state); } diff --git a/html/pages/device/overview/generic/sensor.inc.php b/html/pages/device/overview/generic/sensor.inc.php index bda3d04bd1..6194c37c00 100644 --- a/html/pages/device/overview/generic/sensor.inc.php +++ b/html/pages/device/overview/generic/sensor.inc.php @@ -14,7 +14,7 @@ if (count($sensors)) '); foreach ($sensors as $sensor) { - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); } diff --git a/html/pages/device/overview/mempools.inc.php b/html/pages/device/overview/mempools.inc.php index f11b6beaa2..3d35a8d554 100644 --- a/html/pages/device/overview/mempools.inc.php +++ b/html/pages/device/overview/mempools.inc.php @@ -22,7 +22,7 @@ if (count($mempools)) foreach ($mempools as $mempool) { - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); if($debug) { print_r($state); } diff --git a/html/pages/device/port.inc.php b/html/pages/device/port.inc.php index 944b10a55d..ecb25cfd28 100644 --- a/html/pages/device/port.inc.php +++ b/html/pages/device/port.inc.php @@ -4,7 +4,7 @@ if (!isset($vars['view']) ) { $vars['view'] = "graphs"; } $port = dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($vars['port'])); -if ($config['memcached']['enable']) +if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('port-'.$port['port_id'].'-state'); if($debug) { print_r($state); } diff --git a/html/pages/device/ports.inc.php b/html/pages/device/ports.inc.php index df7c691d6f..b254b376da 100644 --- a/html/pages/device/ports.inc.php +++ b/html/pages/device/ports.inc.php @@ -106,7 +106,7 @@ if ($vars['view'] == 'minigraphs') foreach ($ports as $port) { - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('port-'.$port['port_id'].'-state'); if($debug) { print_r($state); } diff --git a/html/pages/health/sensors.inc.php b/html/pages/health/sensors.inc.php index 82f9862ce0..02224d485c 100644 --- a/html/pages/health/sensors.inc.php +++ b/html/pages/health/sensors.inc.php @@ -26,7 +26,7 @@ echo(' foreach (dbFetchRows($sql, $param) as $sensor) { - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); if($debug) { echo("Memcached[".'sensor-'.$sensor['sensor_id'].'-value'."=".$sensor['sensor_current']."]"); } diff --git a/html/pages/settings.inc.php b/html/pages/settings.inc.php index 8885e131c9..cb2d3ca942 100644 --- a/html/pages/settings.inc.php +++ b/html/pages/settings.inc.php @@ -1,4 +1,5 @@ * 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 @@ -22,11 +23,53 @@ * @subpackage Page */ +?> + +
+
+
+ +
+
+
+ + + +
+
+ + + +
+
+
+"; foreach( $a as $k=>$v ) { @@ -37,10 +80,21 @@ function a2t($a) { $r .= '
'; return $r; } - if( $_SESSION['userlevel'] >= 10 ) { echo "
".a2t($config)."
"; } else { include("includes/error-no-perm.inc.php"); } + + if ($_SESSION['userlevel'] >= '10') { + + if ($debug) { + echo("
");
+            print_r($config);
+            echo("
"); + } + } else { + include("includes/error-no-perm.inc.php"); + } +} ?> diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php new file mode 100644 index 0000000000..ca2473635b --- /dev/null +++ b/html/pages/settings/alerting.inc.php @@ -0,0 +1,894 @@ + + * + * 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. + */ + +$no_refresh = TRUE; + +?> + + + + + + + + + + + + + + +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ +
+
+
+
+
+
+
+

+ Email transport +

+
+
+
+
+ +
+
+ +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+ +
+
+ +
+
+
+ +
+
+ + +
+
+
+ +
+
+ + +
+
+
+
+
+
+
+

+ API transport +

+
+
+
+
+
+ +
+
'; + $api_urls = get_config_like_name('alert.transports.api.%.'); + foreach ($api_urls as $api_url) { + $api_split = split("\.", $api_url['config_name']); + $api_method = $api_split[3]; + echo '
+ +
+ + +
+
+ +
+
'; + } + echo '
+ +
+ + +
+
+ +
+
+
+
+
+
+ +
+
+
+
+ Connect to PagerDuty +
+
'; + if (empty($config_groups['alert.transports.pagerduty']['config_value']) === FALSE) { + echo ""; + } else { + echo ""; + } + echo '
+
+
+
+
+
+ +
+
+
+ +
+
+ + +
+
+
+
+
+
+
+

+ IRC transport +

+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+

+ Slack transport +

+
+
+
+
+
+ +
+
'; + $slack_urls = get_config_like_name('alert.transports.slack.%.url'); + foreach ($slack_urls as $slack_url) { + unset($upd_slack_extra); + $new_slack_extra = array(); + $slack_extras = get_config_like_name('alert.transports.slack.'.$slack_url['config_id'].'.%'); + foreach ($slack_extras as $extra) { + $split_extra = explode('.',$extra['config_name']); + if ($split_extra[4] != 'url') { + $new_slack_extra[] = $split_extra[4] . '=' . $extra['config_value']; + } + } + $upd_slack_extra = implode(PHP_EOL,$new_slack_extra); + echo '
+
+ +
+ + +
+
+ +
+
+
+
+ + +
+
+
'; + } + echo '
+
+ +
+ + +
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+ +
+
'; + $hipchat_urls = get_config_like_name('alert.transports.hipchat.%.url'); + foreach ($hipchat_urls as $hipchat_url) { + unset($upd_hipchat_extra); + $new_hipchat_extra = array(); + $hipchat_extras = get_config_like_name('alert.transports.hipchat.'.$hipchat_url['config_id'].'.%'); + $hipchat_room_id = get_config_by_name('alert.transports.hipchat.'.$hipchat_url['config_id'].'.room_id'); + $hipchat_from = get_config_by_name('alert.transports.hipchat.'.$hipchat_url['config_id'].'.from'); + foreach ($hipchat_extras as $extra) { + $split_extra = explode('.',$extra['config_name']); + if ($split_extra[4] != 'url' && $split_extra[4] != 'room_id' && $split_extra[4] != 'from') { + $new_hipchat_extra[] = $split_extra[4] . '=' . $extra['config_value']; + } + } + $upd_hipchat_extra = implode(PHP_EOL,$new_hipchat_extra); + echo '
+
+ +
+ + +
+
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ + +
+
+
'; + } + echo '
+
+ +
+ + +
+
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ +
+
+
+
+
+
+
+ +'; + +?> + + diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 83b9073d14..9a8105e090 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -191,65 +191,6 @@ $config['autodiscovery']['nets-exclude'][] = "169.254.0.0/16"; $config['autodiscovery']['nets-exclude'][] = "224.0.0.0/4"; $config['autodiscovery']['nets-exclude'][] = "240.0.0.0/4"; -// Mailer backend Settings - -$config['email_backend'] = 'mail'; // Mail backend. Allowed: "mail" (PHP's built-in), "sendmail", "smtp". -$config['email_from'] = NULL; // Mail from. Default: "ProjectName" -$config['email_user'] = $config['project_id']; -$config['email_sendmail_path'] = '/usr/sbin/sendmail'; // The location of the sendmail program. -$config['email_smtp_host'] = 'localhost'; // Outgoing SMTP server name. -$config['email_smtp_port'] = 25; // The port to connect. -$config['email_smtp_timeout'] = 10; // SMTP connection timeout in seconds. -$config['email_smtp_secure'] = NULL; // Enable encryption. Use 'tls' or 'ssl' -$config['email_smtp_auth'] = FALSE; // Whether or not to use SMTP authentication. -$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 - ), - 'syscontact' => true, //Issue to SysContact (or it's override) - 'globals' => false, //Issue to global-read users - 'admins' => false, //Issue to administrators - 'default_only' => false, //Only issue to default - 'default_mail' => '', //Default email - 'tolerance-window' => 10, //Allow +/-10s tolerance to delay values to counter cron-irregularities - 'fixed-contacts' => true, //If true any changes in user-permissions,user-mail,syscontact,default-mail will not be honoured until the next alert triggers. -); - -//Legacy options - -$config['alerts']['email']['default'] = NULL; // Default alert recipient -$config['alerts']['email']['default_only'] = FALSE; // Only use default recipient $config['alerts']['email']['enable'] = FALSE; // Enable email alerts $config['alerts']['bgp']['whitelist'] = NULL; // Populate as an array() with ASNs to alert on. $config['alerts']['port']['ifdown'] = FALSE; // Generate alerts for ports that go down @@ -670,4 +611,7 @@ $config['ipmi']['type'][] = "lan"; $config['ipmi']['type'][] = "imb"; $config['ipmi']['type'][] = "open"; +// Options needed for dyn config - do NOT edit +$dyn_config['email_backend'] = array('mail','sendmail','smtp'); +$dyn_config['email_smtp_secure'] = array('', 'tls', 'ssl'); ?> diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 321de6826f..8fccf9d627 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -1,5 +1,71 @@ MySQL Error"); + echo(mysql_error()); + die; +} +$database_db = mysql_select_db($config['db_name'], $database_link); + +function mergecnf($obj) { +/* Copyright (C) 2014 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 . */ + +/** + * Merge config function + * @author f0o + * @copyright 2015 f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Config + */ + + $pointer = array(); + $val = $obj['config_value']; + $obj = $obj['config_name']; + $obj = explode('.',$obj,2); + if( !isset($obj[1]) ) { + if( filter_var($val,FILTER_VALIDATE_INT) ) { + $val = (int) $val; + } elseif( filter_var($val,FILTER_VALIDATE_FLOAT) ) { + $val = (float) $val; + } elseif( filter_var($val,FILTER_VALIDATE_BOOLEAN,FILTER_NULL_ON_FAILURE) !== NULL ) { + $val = filter_var($val,FILTER_VALIDATE_BOOLEAN); + } + if( !empty($obj[0]) ) { + return array($obj[0] => $val); + } else { + return array($val); + } + } else { + $pointer[$obj[0]] = mergecnf(array('config_name'=>$obj[1],'config_value'=>$val)); + } + return $pointer; +} + +$clone = $config; +foreach( dbFetchRows('select config_name,config_value from config') as $obj ) { + $clone = array_replace_recursive($clone,mergecnf($obj)); +} +$config = array_replace_recursive($clone,$config); + ///////////////////////////////////////////////////////// # NO CHANGES TO THIS FILE, IT IS NOT USER-EDITABLE # ///////////////////////////////////////////////////////// @@ -1742,17 +1808,7 @@ if (isset($_SERVER['HTTPS'])) $config['base_url'] = preg_replace('/^http:/','https:', $config['base_url']); } -// Connect to database -$database_link = mysql_pconnect($config['db_host'], $config['db_user'], $config['db_pass']); -if (!$database_link) -{ - echo("

MySQL Error

"); - echo(mysql_error()); - die; -} -$database_db = mysql_select_db($config['db_name'], $database_link); - -if ($config['memcached']['enable']) +if ($config['memcached']['enable'] === TRUE) { if (class_exists("Memcached")) { diff --git a/includes/functions.php b/includes/functions.php index 1b995bfdb2..9e666c2b0e 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -18,6 +18,7 @@ include_once("Net/IPv4.php"); include_once("Net/IPv6.php"); // Observium Includes +include_once($config['install_dir'] . "/includes/dbFacile.php"); include_once($config['install_dir'] . "/includes/common.php"); include_once($config['install_dir'] . "/includes/rrdtool.inc.php"); @@ -27,7 +28,6 @@ include_once($config['install_dir'] . "/includes/syslog.php"); include_once($config['install_dir'] . "/includes/rewrites.php"); include_once($config['install_dir'] . "/includes/snmp.inc.php"); include_once($config['install_dir'] . "/includes/services.inc.php"); -include_once($config['install_dir'] . "/includes/dbFacile.php"); include_once($config['install_dir'] . "/includes/console_colour.php"); $console_color = new Console_Color2(); diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 873e018cdb..a2ec23be98 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -99,7 +99,7 @@ function poll_sensor($device, $class, $unit) log_event(ucfirst($class) . ' ' . $sensor['sensor_descr'] . " above threshold: " . $sensor_value . " $unit (> " . $sensor['sensor_limit'] . " $unit)", $device, $class, $sensor['sensor_id']); } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $memcache->set('sensor-'.$sensor['sensor_id'].'-value', $sensor_value); } else { diff --git a/includes/polling/mempools.inc.php b/includes/polling/mempools.inc.php index 2d065afe11..abc94a496b 100644 --- a/includes/polling/mempools.inc.php +++ b/includes/polling/mempools.inc.php @@ -46,7 +46,7 @@ foreach (dbFetchRows("SELECT * FROM mempools WHERE device_id = ?", array($device $mempool['state']['mempool_lowestfree'] = $mempool['lowestfree']; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { if($debug) { print_r($mempool['state']); } $memcache->set('mempool-'.$mempool['mempool_id'].'-value', $mempool['state']); diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 429fde3cd9..87d4bdf254 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -164,7 +164,7 @@ foreach ($ports as $port) if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $this_port['ifDescr'], $matches)) { $this_port['ifDescr'] = $matches[1]; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $state = $memcache->get('port-'.$port['port_id'].'-state'); if($debug) { print_r($state); } @@ -184,7 +184,7 @@ foreach ($ports as $port) $port['update']['poll_period'] = $polled_period; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $port['state']['poll_time'] = $polled; $port['state']['poll_prev'] = $port['poll_time']; @@ -303,7 +303,7 @@ foreach ($ports as $port) $port['update'][$oid.'_prev'] = $port[$oid]; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $port['state'][$oid] = $this_port[$oid]; $port['state'][$oid.'_prev'] = $port[$oid]; @@ -323,7 +323,7 @@ foreach ($ports as $port) $port['update'][$oid.'_delta'] = $oid_diff; } - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $port['state'][$oid.'_rate'] = $oid_rate; $port['state'][$oid.'_delta'] = $oid_diff; @@ -356,7 +356,7 @@ foreach ($ports as $port) echo('pkts('.format_si($port['stats']['ifInUcastPkts_rate']).'pps/'.format_si($port['stats']['ifOutUcastPkts_rate']).'pps)'); // Store aggregate in/out state - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $port['state']['ifOctets_rate'] = $port['stats']['ifOutOctets_rate'] + $port['stats']['ifInOctets_rate']; $port['state']['ifUcastPkts_rate'] = $port['stats']['ifOutUcastPkts_rate'] + $port['stats']['ifInUcastPkts_rate']; @@ -434,7 +434,7 @@ foreach ($ports as $port) if ($device['os'] == "aos") { include("port-alcatel.inc.php"); } // Update Memcached - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { if($debug) { print_r($port['state']); } $memcache->set('port-'.$port['port_id'].'-state', $port['state']); diff --git a/includes/polling/storage.inc.php b/includes/polling/storage.inc.php index 2485f822de..4c68d1752d 100644 --- a/includes/polling/storage.inc.php +++ b/includes/polling/storage.inc.php @@ -36,7 +36,7 @@ foreach (dbFetchRows("SELECT * FROM storage WHERE device_id = ?", array($device[ rrdtool_update($storage_rrd,"N:".$storage['used'].":".$storage['free']); - if ($config['memcached']['enable']) + if ($config['memcached']['enable'] === TRUE) { $memcache->set('storage-'.$storage['storage_id'].'-used', $storage['used']); $memcache->set('storage-'.$storage['storage_id'].'-free', $storage['free']); diff --git a/sql-schema/051.sql b/sql-schema/051.sql new file mode 100644 index 0000000000..10fb97fb3b --- /dev/null +++ b/sql-schema/051.sql @@ -0,0 +1,5 @@ +DROP TABLE IF EXISTS `config`; +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_descr` varchar(100) 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=720 DEFAULT CHARSET=latin1; +LOCK TABLES `config` WRITE; +INSERT INTO `config` VALUES (441,'alert.macros.rule.now','NOW()','NOW()','Macro currenttime','alerting',0,'macros',0,'1','0'),(442,'alert.macros.rule.past_5m','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','DATE_SUB(NOW(),INTERVAL 5 MINUTE)','Macro past 5 minutes','alerting',0,'macros',0,'1','0'),(443,'alert.macros.rule.past_10m','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','DATE_SUB(NOW(),INTERVAL 10 MINUTE)','Macro past 10 minutes','alerting',0,'macros',0,'1','0'),(444,'alert.macros.rule.past_15m','DATE_SUB(NOW(),INTERVAL 15 MINUTE)','DATE_SUB(NOW(),INTERVAL 15 MINUTE)','Macro past 15 minutes','alerting',0,'macros',0,'1','0'),(445,'alert.macros.rule.past_30m','DATE_SUB(NOW(),INTERVAL 30 MINUTE)','DATE_SUB(NOW(),INTERVAL 30 MINUTE)','Macro past 30 minutes','alerting',0,'macros',0,'1','0'),(446,'alert.macros.rule.device','(%devices.disabled = 0 && %devices.ignore = 0)','(%devices.disabled = 0 && %devices.ignore = 0)','Devices that aren\'t disabled or ignored','alerting',0,'macros',0,'1','0'),(447,'alert.macros.rule.device_up','(%devices.status = 1 && %macros.device)','(%devices.status = 1 && %macros.device)','Devices that are up','alerting',0,'macros',0,'1','0'),(448,'alert.macros.rule.device_down','(%devices.status = 0 && %macros.device)','(%devices.status = 0 && %macros.device)','Devices that are down','alerting',0,'macros',0,'1','0'),(449,'alert.macros.rule.port','(%ports.deleted = 0 && %ports.ignore = 0 && %ports.disabled = 0)','(%ports.deleted = 0 && %ports.ignore = 0 && %ports.disabled = 0)','Ports that aren\'t disabled, ignored or delete','alerting',0,'macros',0,'1','0'),(450,'alert.macros.rule.port_up','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)','Ports that are up','alerting',0,'macros',0,'1','0'),(451,'alert.admins','true','true','Alert administrators','alerting',0,'general',0,'0','0'),(452,'alert.default_only','true','true','Only alert default mail contact','alerting',0,'general',0,'0','0'),(453,'alert.default_mail','','','The default mail contact','alerting',0,'general',0,'0','0'),(454,'alert.transports.pagerduty','','','Pagerduty transport - put your API key here','alerting',0,'transports',0,'0','0'),(455,'alert.pagerduty.account','','','Pagerduty account name','alerting',0,'transports',0,'0','0'),(456,'alert.pagerduty.service','','','Pagerduty service name','alerting',0,'transports',0,'0','0'),(457,'alert.tolerance_window','5','5','Tolerance window in seconds','alerting',0,'general',0,'0','0'),(458,'email_backend','mail','mail','The backend to use for sending email, can be mail, sendmail or smtp','alerting',0,'general',0,'0','0'),(459,'alert.macros.rule.past_60m','DATE_SUB(NOW(),INTERVAL 60 MINUTE)','DATE_SUB(NOW(),INTERVAL 60 MINUTE)','Macro past 60 minutes','alerting',0,'macros',0,'1','0'),(460,'alert.macros.rule.port_usage_perc','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100','Ports using more than X perc','alerting',0,'macros',0,'1','0'),(461,'alert.transports.dummy','false','false','Dummy transport','alerting',0,'transports',0,'0','0'),(462,'alert.transports.mail','true','true','Mail alerting transport','alerting',0,'transports',0,'0','0'),(463,'alert.transports.irc','FALSE','false','IRC alerting transport','alerting',0,'transports',0,'0','0'),(464,'alert.globals','true','TRUE','Alert read only administrators','alerting',0,'general',0,'0','0'),(465,'email_from','NULL','NULL','Email address used for sending emails (from)','alerting',0,'general',0,'0','0'),(466,'email_user','LibreNMS','LibreNMS','Name used as part of the from address','alerting',0,'general',0,'0','0'),(467,'email_sendmail_path','/usr/sbin/sendmail','/usr/sbin/sendmail','Location of sendmail if using this option','alerting',0,'general',0,'0','0'),(468,'email_smtp_host','localhost','localhost','SMTP Host for sending email if using this option','alerting',0,'general',0,'0','0'),(469,'email_smtp_port','25','25','SMTP port setting','alerting',0,'general',0,'0','0'),(470,'email_smtp_timeout','10','10','SMTP timeout setting','alerting',0,'general',0,'0','0'),(471,'email_smtp_secure','','','Enable / disable encryption (use tls or ssl)','alerting',0,'general',0,'0','0'),(472,'email_smtp_auth','false','FALSE','Enable / disable smtp authentication','alerting',0,'general',0,'0','0'),(473,'email_smtp_username','NULL','NULL','SMTP Auth username','alerting',0,'general',0,'0','0'),(474,'email_smtp_password','NULL','NULL','SMTP Auth password','alerting',0,'general',0,'0','0'),(475,'alert.macros.rule.port_down','(%ports.ifOperStatus = \"down\" && %ports.ifAdminStatus != \"down\" && %macros.port)','(%ports.ifOperStatus = \"down\" && %ports.ifAdminStatus != \"down\" && %macros.port)','Ports that are down','alerting',0,'macros',0,'1','0'),(486,'alert.syscontact','true','TRUE','Issue alerts to sysContact','alerting',0,'general',0,'0','0'),(487,'alert.fixed-contacts','true','TRUE','If TRUE any changes to sysContact or users emails will not be honoured whilst alert is active','alerting',0,'general',0,'0','0'),(488,'alert.transports.nagios','','','Nagios compatible via FIFO','alerting',0,'transports',0,'0','0'); +UNLOCK TABLES;