Merge branch 'master' of https://github.com/adaniels21487/librenms into issue-1650

Conflicts:
	html/api_v0.php
	html/includes/api_functions.inc.php
This commit is contained in:
Aaron Daniels
2015-12-22 11:16:54 +10:00
50 changed files with 3468 additions and 116 deletions
+1 -1
View File
@@ -207,7 +207,7 @@ function IsMaintenance( $device ) {
$where .= " || alert_schedule_items.target = ?";
$params[] = 'g'.$group;
}
return dbFetchCell('SELECT DISTINCT(alert_schedule.schedule_id) FROM alert_schedule LEFT JOIN alert_schedule_items ON alert_schedule.schedule_id=alert_schedule_items.schedule_id WHERE ( alert_schedule_items.target = ?'.$where.' ) && NOW() BETWEEN alert_schedule.start AND alert_schedule.end LIMIT 1',$params);
return dbFetchCell('SELECT alert_schedule.schedule_id FROM alert_schedule LEFT JOIN alert_schedule_items ON alert_schedule.schedule_id=alert_schedule_items.schedule_id WHERE ( alert_schedule_items.target = ?'.$where.' ) && NOW() BETWEEN alert_schedule.start AND alert_schedule.end LIMIT 1',$params);
}
/**
+6 -1
View File
@@ -28,7 +28,12 @@ function dbQuery($sql, $parameters=array()) {
$fullSql = dbMakeQuery($sql, $parameters);
if ($debug) {
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
print $console_color->convert("\nSQL[%y".$fullSql.'%n] ');
if (preg_match('/(INSERT INTO `alert_log`).*(details)/i',$fullSql)) {
echo "\nINSERT INTO `alert_log` entry masked due to binary data\n";
}
else {
print $console_color->convert("\nSQL[%y".$fullSql.'%n] ');
}
}
else {
$sql_debug[] = $fullSql;
+6 -1
View File
@@ -28,7 +28,12 @@ function dbQuery($sql, $parameters=array()) {
$fullSql = dbMakeQuery($sql, $parameters);
if ($debug) {
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
print $console_color->convert("\nSQL[%y".$fullSql.'%n] ');
if (preg_match('/(INSERT INTO `alert_log`).*(details)/i',$fullSql)) {
echo "\nINSERT INTO `alert_log` entry masked due to binary data\n";
}
else {
print $console_color->convert("\nSQL[%y".$fullSql.'%n] ');
}
}
else {
$sql_debug[] = $fullSql;
+10 -6
View File
@@ -110,6 +110,7 @@ $config['os'][$os]['over'][2]['text'] = 'Memory Usage';
$os = 'infinity';
$config['os'][$os]['text'] = 'LigoWave Infinity';
$config['os'][$os]['type'] = 'wireless';
$config['os'][$os]['icon'] = 'ligowave';
$config['os'][$os]['nobulk'] = 1;
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Device Traffic';
@@ -452,7 +453,6 @@ $os = 'nos';
$config['os'][$os]['text'] = 'Brocade NOS';
$config['os'][$os]['type'] = 'network';
$config['os'][$os]['ifname'] = 1;
$config['os'][$os]['descr_to_alias'] = 1;
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Device Traffic';
$config['os'][$os]['over'][1]['graph'] = 'device_processor';
@@ -1380,6 +1380,14 @@ $config['os'][$os]['icon'] = 'riverbed';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Traffic';
// Ligowave LigoOS
$os = 'ligoos';
$config['os'][$os]['text'] = 'LigoWave LigoOS';
$config['os'][$os]['type'] = 'wireless';
$config['os'][$os]['icon'] = 'ligowave';
$config['os'][$os]['over'][0]['graph'] = 'device_bits';
$config['os'][$os]['over'][0]['text'] = 'Traffic';
// Appliances
$os = 'fortios';
$config['os'][$os]['text'] = 'FortiOS';
@@ -1770,10 +1778,6 @@ if (isset($config['rrdgraph_def_text'])) {
$config['rrd_opts_array'] = explode(' ', trim($config['rrdgraph_def_text']));
}
if (!isset($config['log_file'])) {
$config['log_file'] = $config['log_dir'].'/'.$config['project_id'].'.log';
}
if (isset($config['cdp_autocreate'])) {
$config['dp_autocreate'] = $config['cdp_autocreate'];
}
@@ -1842,7 +1846,7 @@ if (!isset($config['log_dir'])) {
}
if (!isset($config['log_file'])) {
$config['log_dir'].'/'.$config['project_id'].'.log';
$config['log_file'] = $config['log_dir'].'/'.$config['project_id'].'.log';
}
if (!isset($config['plugin_dir'])) {
+14 -6
View File
@@ -31,7 +31,7 @@
* @param string $search What to searchid for
* @return string
*/
function GenGroupSQL($pattern, $search='') {
function GenGroupSQL($pattern, $search='',$extra=0) {
$pattern = RunGroupMacros($pattern);
if ($pattern === false) {
return false;
@@ -66,7 +66,11 @@ function GenGroupSQL($pattern, $search='') {
$search .= ' &&';
}
$sql = 'SELECT DISTINCT('.str_replace('(', '', $tables[0]).'.device_id) FROM '.implode(',', $tables).' WHERE '.$search.' ('.str_replace(array('%', '@', '!~', '~'), array('', '.*', 'NOT REGEXP', 'REGEXP'), $pattern).')';
$sql_extra = '';
if ($extra === 1) {
$sql_extra = ",`devices`.*";
}
$sql = 'SELECT DISTINCT('.str_replace('(', '', $tables[0]).'.device_id)'.$sql_extra.' FROM '.implode(',', $tables).' WHERE '.$search.' ('.str_replace(array('%', '@', '!~', '~'), array('', '.*', 'NOT REGEXP', 'REGEXP'), $pattern).')';
return $sql;
}//end GenGroupSQL()
@@ -99,17 +103,21 @@ function GetDeviceGroups() {
}//end GetDeviceGroups()
/**
* Get all groups of Device
* @param integer $device Device-ID
* @return array
*/
function GetGroupsFromDevice($device) {
function GetGroupsFromDevice($device,$extra=0) {
$ret = array();
foreach (GetDeviceGroups() as $group) {
if (dbFetchCell(GenGroupSQL($group['pattern'], 'device_id=?').' LIMIT 1', array($device)) == $device) {
$ret[] = $group['id'];
if (dbFetchCell(GenGroupSQL($group['pattern'], 'device_id=?',$extra).' LIMIT 1', array($device)) == $device) {
if ($extra === 0) {
$ret[] = $group['id'];
}
else {
$ret[] = $group;
}
}
}
+16 -4
View File
@@ -143,12 +143,24 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) {
if (!$remote_device_id && is_valid_hostname($lldp['lldpRemSysName'])) {
$remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface);
}
// normalize MAC address if present
if ($lldp['lldpRemChassisIdSubtype'] == 'macAddress') {
$remote_mac_address = str_replace(array(' ', ':', '-'), '', strtolower($lldp['lldpRemChassisId']));
}
// get remote device hostname from db by MAC address and replace lldpRemSysName if absent
if (!$remote_device_id && $remote_mac_address) {
$remote_device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE ifPhysAddress = ? AND `deleted` = ?', array($remote_mac_address, '0'));
if ($remote_device_id) {
$remote_device_hostname = dbFetchRow('SELECT `hostname` FROM `devices` WHERE `device_id` = ?', array($remote_device_id));
}
if ($remote_device_hostname['hostname']) {
$lldp['lldpRemSysName'] = $remote_device_hostname['hostname'];
}
}
if ($remote_device_id) {
$if = $lldp['lldpRemPortDesc'];
$id = $lldp['lldpRemPortId'];
$PhysAddress = preg_replace('/ /', '', $id);
$remote_port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ? OR `ifPhysAddress` = ?) AND `device_id` = ?', array($if, $if, $id, $id, $PhysAddress, $remote_device_id));
$remote_port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ? OR `ifPhysAddress` = ?) AND `device_id` = ?', array($if, $if, $id, $id, $remote_mac_address, $remote_device_id));
}
else {
$remote_port_id = '0';
@@ -163,7 +175,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) {
}//end if
}//end elseif
echo 'OSPF Discovery: ';
echo ' OSPF Discovery: ';
if ($config['autodiscovery']['ospf'] === true) {
echo "enabled\n";
@@ -31,6 +31,10 @@ if (is_array($storage_array)) {
break;
}
if ($device['os'] == 'vmware' && $descr == 'Real Memory') {
$deny = 0;
}
if ($device['os'] == 'routeros' && $descr == 'main memory') {
$deny = 0;
}
+15
View File
@@ -0,0 +1,15 @@
<?php
if ($device['os'] == "nos") {
echo("nos: ");
$used = snmp_get($device, "1.3.6.1.4.1.1588.2.1.1.1.26.6.0", "-Ovq");
$total = "100";
$free = ($total - $used);
$percent = $used;
if (is_numeric($used)) {
discover_mempool($valid_mempool, $device, 0, "nos", "Memory", "1", NULL, NULL);
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
if (!$os) {
if (strstr($sysObjectId, '.1.3.6.1.4.1.4413') && !stristr($sysDescr, 'vxworks')) {
if (strstr($sysObjectId, '.1.3.6.1.4.1.4413') && (!stristr($sysDescr, 'vxworks') && !stristr($sysDescr, 'Quanta'))) {
$os = 'edgeswitch';
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2015 Søren Friis Rosiak <sorenrosiak@gmail.com>
* 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 (!$os) {
if (preg_match('/^LigoPTP/', $sysDescr)) {
$os = 'ligoos';
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
<?php
if (!$os) {
if (strstr($sysObjectId, '.1.3.6.1.4.1.1588.2.2.1.1.1.5') || stristr($sysDescr, 'Brocade Communications Systems')) {
$os = 'nos';
if (strstr($sysDescr, "Brocade VDX") || strstr($sysObjectId, '.1.3.6.1.4.1.1588.2.2.1.1.1.5') || stristr($sysDescr, 'Brocade Communications Systems')) {
$os = "nos";
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
if (!$os) {
if (strstr($sysObjectId, '.1.3.6.1.4.1.4413') && stristr($sysDescr, 'vxworks')) {
if (strstr($sysObjectId, '.1.3.6.1.4.1.4413') && (stristr($sysDescr, 'vxworks') || stristr($sysDescr, 'Quanta'))) {
$os = 'quanta';
}
}
@@ -1,18 +1,31 @@
<?php
//
// Hardcoded discovery of cpu usage on Fortigate devices.
// Somewhat dynamic processor discovery for Fortigate boxes.
//
// FORTINET-FORTIGATE-MIB::fgSysCpuUsage.0
// FORTINET-FORTIGATE-MIB::fgSysCpuUsage.X where X is the CPU number
// FORTINET-FORTIGATE-MIB::fgProcModDescr.X where X is the CPU number
// FORTINET-FORTIGATE-MIB::fgProcessorCount.0 -> Num CPUs in the device
if ($device['os'] == 'fortigate') {
echo 'Fortigate : ';
echo 'Fortigate : ';
$descr = 'Processor';
$usage = snmp_get($device, '.1.3.6.1.4.1.12356.101.4.1.3.0', '-Ovq');
// Forti have logical CPU numbering - start at 1 and increment to $num_cpu in the box.
$num_cpu = snmp_get($device, 'FORTINET-FORTIGATE-MIB::fgProcessorCount.0', '-Ovq');
if (is_numeric($usage)) {
discover_processor($valid['processor'], $device, '.1.3.6.1.4.1.12356.101.4.1.3.0', '0', 'fortigate-fixed', $descr, '1', $usage, null, null);
}
}
print "Forti-found $num_cpu CPUs\n";
for($i = 1; $i <= $num_cpu; $i++) {
// HERP DERP IM A FORTIGATE AND I PUT NON NUMERIC VALUES IN A GAUGE
$cpu_usage = snmp_get($device, "FORTINET-FORTIGATE-MIB::fgProcessorUsage.$i", '-Ovq');
$usage = trim ( str_replace(" %", "", $cpu_usage ) ) ;
$descr = snmp_get($device, "FORTINET-FORTIGATE-MIB::fgProcModDescr.$i", '-Ovq');
print "CPU: $num_cpu - USAGE: $cpu_usage - TYPE $descr\n";
if (is_numeric($usage)) {
discover_processor($valid['processor'], $device, "FORTINET-FORTIGATE-MIB::fgProcessorUsage." . $num_cpu, '0', 'fortigate-fixed', $descr, '1', $usage, null, null);
}
} // END For loop for CPU discovery
} // END if device is Fortigate
unset($processors_array);
+14
View File
@@ -0,0 +1,14 @@
<?php
if ($device['os'] == "nos") {
echo("nos : ");
$descr = "CPU";
$usage = snmp_get($device, "1.3.6.1.4.1.1588.2.1.1.1.26.1.0", "-Ovq");
if (is_numeric($usage)) {
discover_processor($valid['processor'], $device, "1.3.6.1.4.1.1588.2.1.1.1.26.1", "0", "nos", $descr, "1", $usage, NULL, NULL);
}
}
unset ($processors_array);
@@ -33,6 +33,13 @@ if (is_array($hrstorage_array)) {
break;
}
if ($device['os'] == 'vmware' && $descr == 'Real Memory') {
$old_rrdfile = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('storage-hrstorage-'.safename($descr).'.rrd');
$new_rrdfile = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('mempool-hrstorage-'.$storage['hrStorageIndex'].'.rrd');
rename($old_rrdfile, $new_rrdfile);
$deny = 1;
}
foreach ($config['ignore_mount'] as $bi) {
if ($bi == $descr) {
$deny = 1;
@@ -109,6 +109,7 @@ $mapping = array(
);
$values = array();
unset($fields);
foreach ($mapping as $k => $v) {
$fields[$k] = isset($map[$v]) ? $map[$v] : (-1);
}
+1 -1
View File
@@ -119,7 +119,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']);
}
dbUpdate(array('sensor_current' => $sensor_value), 'sensors', '`sensor_class` = ? AND `sensor_id` = ?', array($class, $sensor['sensor_id']));
dbUpdate(array('sensor_current' => $sensor_value, 'lastupdate' => array('NOW()')), 'sensors', '`sensor_class` = ? AND `sensor_id` = ?', array($class, $sensor['sensor_id']));
}//end foreach
}//end poll_sensor()
+1 -1
View File
@@ -50,7 +50,7 @@ if ($ipmi['host'] = get_dev_attrib($device, 'ipmi_hostname')) {
rrdtool_update($rrd_file, $fields);
// FIXME warnings in event & mail not done here yet!
dbUpdate(array('sensor_current' => $sensor), 'sensors', 'poller_type = ? AND sensor_class = ? AND sensor_id = ?', array('ipmi', $ipmisensors['sensor_class'], $ipmisensors['sensor_id']));
dbUpdate(array('sensor_current' => $sensor, 'lastupdate' => array('NOW()')), 'sensors', 'poller_type = ? AND sensor_class = ? AND sensor_id = ?', array('ipmi', $ipmisensors['sensor_class'], $ipmisensors['sensor_id']));
}
unset($ipmi_sensor);
+7
View File
@@ -0,0 +1,7 @@
<?php
// Somewhat of an uggly hack since NOS doesn't support fetching total memory of the device over SNMP
// Given OID returns usage in percent so we set total to 100 in order to get a proper graph
$mempool['total'] = "100";
$mempool['used'] = snmp_get($device, "1.3.6.1.4.1.1588.2.1.1.1.26.6.0", "-Ovq");
$mempool['free'] = ($mempool['total'] - $mempool['used']);
-17
View File
@@ -33,21 +33,4 @@ if (is_numeric($sessions)) {
$graphs['fortigate_sessions'] = true;
}
$cpurrd = $config['rrd_dir'].'/'.$device['hostname'].'/fortigate_cpu.rrd';
$cpu_usage = snmp_get($device, 'FORTINET-FORTIGATE-MIB::fgSysCpuUsage.0', '-Ovq');
if (is_numeric($cpu_usage)) {
if (!is_file($cpurrd)) {
rrdtool_create($cpurrd, ' --step 300 DS:LOAD:GAUGE:600:-1:100 '.$config['rrd_rra']);
}
echo "CPU: $cpu_usage%\n";
$fields = array(
'LOAD' => $cpu_usage,
);
rrdtool_update($cpurrd, $fields);
$graphs['fortigate_cpu'] = true;
}
+15
View File
@@ -0,0 +1,15 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2015 Søren Friis Rosiak <sorenrosiak@gmail.com>
* 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.
*/
list($hardware,$version) = explode(',', $poll_device['sysDescr']);
preg_match('/(v[0-9\-\.]+)/', $version, $tmp_version);
$version = rtrim($tmp_version[0],'.');
+3 -4
View File
@@ -1,6 +1,5 @@
<?php
// SNMPv2-MIB::sysDescr.0 Brocade VDX Switch.
if (preg_match('/Brocade ([\s\d\w]+)/', $poll_device['sysDescr'], $hardware)) {
$hardware = $hardware[1];
}
$version = trim(snmp_get($device, "1.3.6.1.4.1.1588.2.1.1.1.1.6.0", "-Ovq"),'"');
$hardware = trim(snmp_get($device, "ENTITY-MIB::entPhysicalDescr.1", "-Ovq"),'"');
$serial = trim(snmp_get($device, "1.3.6.1.2.1.47.1.1.1.1.11.1", "-Ovq"),'"');
+1 -1
View File
@@ -354,7 +354,7 @@ foreach ($ports as $port) {
echo 'VLAN == '.$this_port['ifVlan'];
// When devices do not provide ifAlias data, populate with ifDescr data if configured
if (($this_port['ifAlias'] == '' || $this_port['ifAlias'] == NULL) || $config['os'][$device['os']]['descr_to_alias'] == 1) {
if ($this_port['ifAlias'] == '' || $this_port['ifAlias'] == NULL) {
$this_port['ifAlias'] = $this_port['ifDescr'];
d_echo('Using ifDescr as ifAlias');
}
+3
View File
@@ -0,0 +1,3 @@
<?php
$proc = trim(snmp_get($device, "1.3.6.1.4.1.1588.2.1.1.1.26.1.0", "-Ovq"),'"');
+1 -1
View File
@@ -9,7 +9,7 @@ if( !empty($service['service_ip']) ) {
$cmd .= " ".$service['service_param'];
$check = shell_exec($cmd);
list($check, $time) = split("\|", $check);
list($check, $time) = explode("\|", $check);
if(strstr($check, "SSL_CERT OK")) {
$status = '1';