From f971d7ecf351cb9425c9d19f67f8d79cc77a6338 Mon Sep 17 00:00:00 2001 From: Peter Lamperud Date: Mon, 16 Nov 2015 12:27:15 +0100 Subject: [PATCH 01/10] Signed-off-by: Peter Lamperud --- html/includes/authentication/active_directory.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/html/includes/authentication/active_directory.inc.php b/html/includes/authentication/active_directory.inc.php index a562ae9010..e2d85907f1 100644 --- a/html/includes/authentication/active_directory.inc.php +++ b/html/includes/authentication/active_directory.inc.php @@ -1,6 +1,7 @@ Date: Mon, 16 Nov 2015 13:37:12 +0100 Subject: [PATCH 02/10] Functionality added: adduser(), user_exists_in_db() --- .../authentication/active_directory.inc.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/html/includes/authentication/active_directory.inc.php b/html/includes/authentication/active_directory.inc.php index e2d85907f1..d4f2ef3319 100644 --- a/html/includes/authentication/active_directory.inc.php +++ b/html/includes/authentication/active_directory.inc.php @@ -1,7 +1,6 @@ $username, 'user_id' => get_userid($username), 'level' => "0", 'can_modify_passwd' => 0, 'twofactor' => 0), 'users'); + } + else { + return false; + } } +function user_exists_in_db($username) { + $return = @dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username), true); + return $return; +} function user_exists($username) { global $config, $ds; From dce37d2f347fbd02daa64feb5be31a88c4f4de77 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 16 Nov 2015 21:42:40 +0000 Subject: [PATCH 03/10] Eventlog query now uses event_id as already indexed --- html/includes/table/eventlog.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/includes/table/eventlog.inc.php b/html/includes/table/eventlog.inc.php index 797b71d777..62edbbefd3 100644 --- a/html/includes/table/eventlog.inc.php +++ b/html/includes/table/eventlog.inc.php @@ -29,7 +29,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { $sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `E`.`datetime` LIKE '%$searchPhrase%' OR `E`.`message` LIKE '%$searchPhrase%' OR `E`.`type` LIKE '%$searchPhrase%')"; } -$count_sql = "SELECT COUNT(datetime) $sql"; +$count_sql = "SELECT COUNT(event_id) $sql"; $total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; From af8df3469c2096f27a213500d40ba8eaef518640 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 17 Nov 2015 00:20:06 +0000 Subject: [PATCH 04/10] Added support for per device unix-agent port --- html/includes/functions.inc.php | 3 +++ html/js/librenms.js | 26 ++++++++++++++++++++++++++ html/pages/device/edit/misc.inc.php | 6 ++++++ html/pages/settings/external.inc.php | 16 ++++++++++++++++ includes/polling/unix-agent.inc.php | 16 ++++++++++++---- sql-schema/076.sql | 1 + 6 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 sql-schema/076.sql diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 21121d0cef..e6c7f0ccad 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -1178,6 +1178,9 @@ function dynamic_override_config($type, $name, $device) { if ($type == 'checkbox') { return ''; } + elseif ($type == 'text') { + return ''; + } }//end dynamic_override_config() function generate_dynamic_config_panel($title,$end_panel=true,$config_groups,$items=array(),$transport='') { diff --git a/html/js/librenms.js b/html/js/librenms.js index 576362bc66..3df1fc5338 100644 --- a/html/js/librenms.js +++ b/html/js/librenms.js @@ -25,6 +25,32 @@ $(document).ready(function() { }); }); + // Device override for text inputs + $(document).on('blur', 'input[name="override_config_text"]', function(event) { + event.preventDefault(); + var $this = $(this); + var attrib = $this.data('attrib'); + var device_id = $this.data('device_id'); + var value = $this.val(); + $.ajax({ + type: 'POST', + url: 'ajax_form.php', + data: { type: 'override-config', device_id: device_id, attrib: attrib, state: value }, + dataType: 'json', + success: function(data) { + if (data.status == 'ok') { + toastr.success(data.message); + } + else { + toastr.error(data.message); + } + }, + error: function() { + toastr.error('Could not set this override'); + } + }); + }); + // Checkbox config ajax calls $("[name='global-config-check']").bootstrapSwitch('offColor','danger'); $('input[name="global-config-check"]').on('switchChange.bootstrapSwitch', function(event, state) { diff --git a/html/pages/device/edit/misc.inc.php b/html/pages/device/edit/misc.inc.php index a856898523..d1731ecdfd 100644 --- a/html/pages/device/edit/misc.inc.php +++ b/html/pages/device/edit/misc.inc.php @@ -14,6 +14,12 @@ echo ' '.dynamic_override_config('checkbox','override_Oxidized_disable', $device).' +
+ +
+ '.dynamic_override_config('text','override_Unixagent_port', $device).' +
+
'; diff --git a/html/pages/settings/external.inc.php b/html/pages/settings/external.inc.php index 2960b2e259..5459ed67eb 100644 --- a/html/pages/settings/external.inc.php +++ b/html/pages/settings/external.inc.php @@ -19,12 +19,28 @@ $oxidized_conf = array( ), ); +$unixagent_conf = array( + array('name' => 'unix-agent.port', + 'descr' => 'Default unix-agent port', + 'type' => 'text', + ), + array('name' => 'unix-agent.connection-timeout', + 'descr' => 'Connection timeout', + 'type' => 'text', + ), + array('name' => 'unix-agent.read-timeout', + 'descr' => 'Read timeout', + 'type' => 'text', + ), +); + echo '
'; echo generate_dynamic_config_panel('Oxidized integration',true,$config_groups,$oxidized_conf); +echo generate_dynamic_config_panel('Unix-agent integration',true,$config_groups,$unixagent_conf); echo '
diff --git a/includes/polling/unix-agent.inc.php b/includes/polling/unix-agent.inc.php index 18d30e58e0..a10ce93338 100644 --- a/includes/polling/unix-agent.inc.php +++ b/includes/polling/unix-agent.inc.php @@ -3,14 +3,22 @@ if ($device['os_group'] == 'unix') { echo $config['project_name'].' UNIX Agent: '; - // FIXME - this should be in config and overridable in database - $agent_port = '6556'; + $agent_port = get_dev_attrib($device,'override_Unixagent_port'); + if (empty($agent_port)) { + $agent_port = $config['unix-agent']['port']; + } + if (empty($config['unix-agent']['connection-timeout'])) { + $config['unix-agent']['connection-timeout'] = $config['unix-agent-connection-time-out']; + } + if (empty($config['unix-agent']['read-timeout'])) { + $config['unix-agent']['read-timeout'] = $config['unix-agent-read-time-out']; + } $agent_start = utime(); - $agent = fsockopen($device['hostname'], $agent_port, $errno, $errstr, $config['unix-agent-connection-time-out']); + $agent = fsockopen($device['hostname'], $agent_port, $errno, $errstr, $config['unix-agent']['connection-timeout']); // Set stream timeout (for timeouts during agent fetch - stream_set_timeout($agent, $config['unix-agent-read-time-out']); + stream_set_timeout($agent, $config['unix-agent']['read-timeout']); $agentinfo = stream_get_meta_data($agent); if (!$agent) { diff --git a/sql-schema/076.sql b/sql-schema/076.sql new file mode 100644 index 0000000000..80cb87c4aa --- /dev/null +++ b/sql-schema/076.sql @@ -0,0 +1 @@ +INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('unix-agent.port','6556','6556','Default port for the Unix-agent (check_mk)','external',0,'unix-agent',0,'0','0'),('unix-agent.connection-timeout','10','10','Unix-agent connection timeout','external',0,'unix-agent',0,'0','0'),('unix-agent.read-timeout','10','10','Unix-agent read timeout','external',0,'unix-agent',0,'0','0'); From 87d273fc7d540e56e05652963e356f7b05824cee Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 16 Nov 2015 20:58:16 -0800 Subject: [PATCH 05/10] Removed / from link for installs not in / --- html/includes/print-map.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index eb41929fe2..d512a7e21a 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -218,7 +218,7 @@ echo $edges; var network = new vis.Network(container, data, options); network.on('click', function (properties) { if (properties.nodes > 0) { - window.location.href = "/device/device="+properties.nodes+"/tab=map/" + window.location.href = "device/device="+properties.nodes+"/tab=map/" } }); From 8660745b927f161840b1e8a83f2fe9915f8b0293 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 16 Nov 2015 21:07:50 -0800 Subject: [PATCH 06/10] Added missing fields when inserting into applications table --- html/pages/device/edit/apps.inc.php | 4 ++-- includes/polling/unix-agent.inc.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/html/pages/device/edit/apps.inc.php b/html/pages/device/edit/apps.inc.php index c885666dfc..fc5e50eea2 100644 --- a/html/pages/device/edit/apps.inc.php +++ b/html/pages/device/edit/apps.inc.php @@ -36,7 +36,7 @@ if ($_POST['device']) { foreach ($enabled as $app) { if (!in_array($app, $app_in_db)) { - $updated += dbInsert(array('device_id' => $device['device_id'], 'app_type' => $app), 'applications'); + $updated += dbInsert(array('device_id' => $device['device_id'], 'app_type' => $app, 'app_status' => '', 'app_instance' => ''), 'applications'); } } @@ -99,4 +99,4 @@ echo '
'; echo ''; echo '
'; -echo '
'; \ No newline at end of file +echo ''; diff --git a/includes/polling/unix-agent.inc.php b/includes/polling/unix-agent.inc.php index 18d30e58e0..a76b896140 100644 --- a/includes/polling/unix-agent.inc.php +++ b/includes/polling/unix-agent.inc.php @@ -108,7 +108,7 @@ if ($device['os_group'] == 'unix') { if (in_array($key, array('apache', 'mysql', 'nginx', 'proxmox', 'ceph'))) { if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?', array($device['device_id'], $key)) == '0') { echo "Found new application '$key'\n"; - dbInsert(array('device_id' => $device['device_id'], 'app_type' => $key), 'applications'); + dbInsert(array('device_id' => $device['device_id'], 'app_type' => $key, 'app_status' => '', 'app_instance' => ''), 'applications'); } } } @@ -120,7 +120,7 @@ if ($device['os_group'] == 'unix') { foreach ($agent_data['app']['memcached'] as $memcached_host => $memcached_data) { if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ? AND `app_instance` = ?', array($device['device_id'], 'memcached', $memcached_host)) == '0') { echo "Found new application 'Memcached' $memcached_host\n"; - dbInsert(array('device_id' => $device['device_id'], 'app_type' => 'memcached', 'app_instance' => $memcached_host), 'applications'); + dbInsert(array('device_id' => $device['device_id'], 'app_type' => 'memcached', 'app_status' => '', 'app_instance' => $memcached_host), 'applications'); } } } @@ -134,7 +134,7 @@ if ($device['os_group'] == 'unix') { $agent_data['app']['drbd'][$drbd_dev] = $drbd_data; if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ? AND `app_instance` = ?', array($device['device_id'], 'drbd', $drbd_dev)) == '0') { echo "Found new application 'DRBd' $drbd_dev\n"; - dbInsert(array('device_id' => $device['device_id'], 'app_type' => 'drbd', 'app_instance' => $drbd_dev), 'applications'); + dbInsert(array('device_id' => $device['device_id'], 'app_type' => 'drbd', 'app_status' => '', 'app_instance' => $drbd_dev), 'applications'); } } } From 6e78fc8d0b7f846e1371112bb198773b5f3ab624 Mon Sep 17 00:00:00 2001 From: vizay Date: Tue, 17 Nov 2015 12:28:28 +0100 Subject: [PATCH 07/10] Update active_directory.inc.php --- html/includes/authentication/active_directory.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/includes/authentication/active_directory.inc.php b/html/includes/authentication/active_directory.inc.php index d4f2ef3319..a1dd80f86a 100644 --- a/html/includes/authentication/active_directory.inc.php +++ b/html/includes/authentication/active_directory.inc.php @@ -94,7 +94,7 @@ function adduser($username) { } function user_exists_in_db($username) { - $return = @dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username), true); + $return = dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username), true); return $return; } From f7ad46ef1c2482d16ca278f8447361513fb09bb2 Mon Sep 17 00:00:00 2001 From: vizay Date: Tue, 17 Nov 2015 12:33:17 +0100 Subject: [PATCH 08/10] Update AUTHORS.md --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 4c3d6983bf..0b495e5b1a 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -69,4 +69,5 @@ Contributors to LibreNMS: - Rob Gormley (rgormley) - Richard Kojedzinszky (rkojedzinszky) - Tony Murray (murrant) +- Peter Lamperud (vizay) [1]: http://observium.org/ "Observium web site" From 139e6f1aef84d7a5479bed43e063067e46982cea Mon Sep 17 00:00:00 2001 From: vizay Date: Tue, 17 Nov 2015 12:33:58 +0100 Subject: [PATCH 09/10] Update AUTHORS.md --- AUTHORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index 0b495e5b1a..72c7354353 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -69,5 +69,5 @@ Contributors to LibreNMS: - Rob Gormley (rgormley) - Richard Kojedzinszky (rkojedzinszky) - Tony Murray (murrant) -- Peter Lamperud (vizay) +- Peter Lamperud (vizay) [1]: http://observium.org/ "Observium web site" From f9c69419f425151ce6ae8ca63eef7f050ddb1b0c Mon Sep 17 00:00:00 2001 From: vizay Date: Tue, 17 Nov 2015 12:35:36 +0100 Subject: [PATCH 10/10] I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md. --- AUTHORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index 72c7354353..0b495e5b1a 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -69,5 +69,5 @@ Contributors to LibreNMS: - Rob Gormley (rgormley) - Richard Kojedzinszky (rkojedzinszky) - Tony Murray (murrant) -- Peter Lamperud (vizay) +- Peter Lamperud (vizay) [1]: http://observium.org/ "Observium web site"