From 98aba4307fd3f2607753146b3c466f5e5befb8c3 Mon Sep 17 00:00:00 2001 From: Micah Chasteen Date: Thu, 12 Feb 2015 11:36:57 -0700 Subject: [PATCH 01/22] Fixed the INSERT line in build.sql so that graph order is always an int value of 0. --- build.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sql b/build.sql index a4b3897b9c..fef772e5ee 100644 --- a/build.sql +++ b/build.sql @@ -78,7 +78,7 @@ CREATE TABLE IF NOT EXISTS `perf_times` ( `type` varchar(8) NOT NULL, `doing` ## 0.10.7.1 CREATE TABLE IF NOT EXISTS `device_graphs` ( `device_id` int(11) NOT NULL, `graph` varchar(32) COLLATE utf8_unicode_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `graph_types` ( `graph_type` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `graph_subtype` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `graph_section` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `graph_descr` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `graph_order` int(11) NOT NULL, KEY `graph_type` (`graph_type`), KEY `graph_subtype` (`graph_subtype`), KEY `graph_section` (`graph_section`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -INSERT INTO `graph_types` (`graph_type`, `graph_subtype`, `graph_section`, `graph_descr`, `graph_order`) VALUES('device', 'bits', 'netstats', 'Total Traffic', 0),('device', 'hr_users', 'system', 'Users Logged In', 0),('device', 'ucd_load', 'system', 'Load Averages', 0),('device', 'ucd_cpu', 'system', 'Detailed Processor Usage', 0),('device', 'ucd_memory', 'system', 'Detailed Memory Usage', 0),('device', 'netstat_tcp', 'netstats', 'TCP Statistics', 0),('device', 'netstat_icmp_info', 'netstats', 'ICMP Informational Statistics', 0),('device', 'netstat_icmp_stat', 'netstats', 'ICMP Statistics', 0),('device', 'netstat_ip', 'netstats', 'IP Statistics', 0),('device', 'netstat_ip_frag', 'netstats', 'IP Fragmentation Statistics', 0),('device', 'netstat_udp', 'netstats', 'UDP Statistics', 0),('device', 'netstat_snmp', 'netstats', 'SNMP Statistics', 0),('device', 'temperatures', 'system', 'Temperatures', 0),('device', 'mempools', 'system', 'Memory Pool Usage', 0),('device', 'processors', 'system', 'Processor Usage', 0),('device', 'storage', 'system', 'Filesystem Usage', 0),('device', 'hr_processes', 'system', 'Running Processes', 0),('device', 'uptime', 'system', 'System Uptime', ''),('device', 'ipsystemstats_ipv4', 'netstats', 'IPv4 Packet Statistics', 0),('device', 'ipsystemstats_ipv6_frag', 'netstats', 'IPv6 Fragmentation Statistics', 0),('device', 'ipsystemstats_ipv6', 'netstats', 'IPv6 Packet Statistics', 0),('device', 'ipsystemstats_ipv4_frag', 'netstats', 'IPv4 Fragmentation Statistics', 0),('device', 'fortigate_sessions', 'firewall', 'Active Sessions', ''), ('device', 'screenos_sessions', 'firewall', 'Active Sessions', ''), ('device', 'fdb_count', 'system', 'MAC Addresses Learnt', '0'),('device', 'cras_sessions', 'firewall', 'Remote Access Sessions', 0); +INSERT INTO `graph_types` (`graph_type`, `graph_subtype`, `graph_section`, `graph_descr`, `graph_order`) VALUES('device', 'bits', 'netstats', 'Total Traffic', 0),('device', 'hr_users', 'system', 'Users Logged In', 0),('device', 'ucd_load', 'system', 'Load Averages', 0),('device', 'ucd_cpu', 'system', 'Detailed Processor Usage', 0),('device', 'ucd_memory', 'system', 'Detailed Memory Usage', 0),('device', 'netstat_tcp', 'netstats', 'TCP Statistics', 0),('device', 'netstat_icmp_info', 'netstats', 'ICMP Informational Statistics', 0),('device', 'netstat_icmp_stat', 'netstats', 'ICMP Statistics', 0),('device', 'netstat_ip', 'netstats', 'IP Statistics', 0),('device', 'netstat_ip_frag', 'netstats', 'IP Fragmentation Statistics', 0),('device', 'netstat_udp', 'netstats', 'UDP Statistics', 0),('device', 'netstat_snmp', 'netstats', 'SNMP Statistics', 0),('device', 'temperatures', 'system', 'Temperatures', 0),('device', 'mempools', 'system', 'Memory Pool Usage', 0),('device', 'processors', 'system', 'Processor Usage', 0),('device', 'storage', 'system', 'Filesystem Usage', 0),('device', 'hr_processes', 'system', 'Running Processes', 0),('device', 'uptime', 'system', 'System Uptime', 0),('device', 'ipsystemstats_ipv4', 'netstats', 'IPv4 Packet Statistics', 0),('device', 'ipsystemstats_ipv6_frag', 'netstats', 'IPv6 Fragmentation Statistics', 0),('device', 'ipsystemstats_ipv6', 'netstats', 'IPv6 Packet Statistics', 0),('device', 'ipsystemstats_ipv4_frag', 'netstats', 'IPv4 Fragmentation Statistics', 0),('device', 'fortigate_sessions', 'firewall', 'Active Sessions', 0), ('device', 'screenos_sessions', 'firewall', 'Active Sessions', 0), ('device', 'fdb_count', 'system', 'MAC Addresses Learnt', 0),('device', 'cras_sessions', 'firewall', 'Remote Access Sessions', 0); CREATE TABLE IF NOT EXISTS `vminfo` (`id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `vmwVmVMID` int(11) NOT NULL, `vmwVmDisplayName` varchar(128) NOT NULL, `vmwVmGuestOS` varchar(128) NOT NULL, `vmwVmMemSize` int(11) NOT NULL, `vmwVmCpus` int(11) NOT NULL, `vmwVmState` varchar(128) NOT NULL, PRIMARY KEY (`id`), KEY `device_id` (`device_id`), KEY `vmwVmVMID` (`vmwVmVMID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `cef_switching` ( `device_id` int(11) NOT NULL, `entPhysicalIndex` int(11) NOT NULL, `afi` varchar(4) COLLATE utf8_unicode_ci NOT NULL, `cef_index` int(11) NOT NULL, `cef_path` varchar(16) COLLATE utf8_unicode_ci NOT NULL, `drop` int(11) NOT NULL, `punt` int(11) NOT NULL, `punt2host` int(11) NOT NULL, `drop_prev` int(11) NOT NULL, `punt_prev` int(11) NOT NULL, `punt2host_prev` int(11) NOT NULL,`updated` INT NOT NULL , `updated_prev` INT NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; UPDATE sensors SET sensor_class='frequency' WHERE sensor_class='freq'; From a1ef2e0f69e8fc4f1725166fdca5c3e697d1f266 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Fri, 13 Feb 2015 11:30:10 -0700 Subject: [PATCH 02/22] Fixed the mysql auth include and the db schema. I set the desc field to be a varchar(200) and set it to be NULL by default (this is a personal preference but since it was not set in the code...). I fixed adduser function in html/includes/authentication/mysql.inc.php. I added $description and $twofactor to the function argument with default values and added descr and twofactor elements in the array passed to the dbInsert function call. OpenSuSE 13.2 --- build.sql | 2 +- html/includes/authentication/mysql.inc.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.sql b/build.sql index fef772e5ee..9f45260698 100644 --- a/build.sql +++ b/build.sql @@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS `storage` ( `storage_id` int(11) NOT NULL AUTO_INCREM CREATE TABLE IF NOT EXISTS `syslog` ( `device_id` int(11) DEFAULT NULL, `facility` varchar(10) DEFAULT NULL, `priority` varchar(10) DEFAULT NULL, `level` varchar(10) DEFAULT NULL, `tag` varchar(10) DEFAULT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `program` varchar(32) DEFAULT NULL, `msg` text, `seq` bigint(20) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`seq`), KEY `datetime` (`timestamp`), KEY `device_id` (`device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `toner` ( `toner_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL DEFAULT '0', `toner_index` int(11) NOT NULL, `toner_type` varchar(64) NOT NULL, `toner_oid` varchar(64) NOT NULL, `toner_descr` varchar(32) NOT NULL DEFAULT '', `toner_capacity` int(11) NOT NULL DEFAULT '0', `toner_current` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`toner_id`), KEY `device_id` (`device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `ucd_diskio` ( `diskio_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `diskio_index` int(11) NOT NULL, `diskio_descr` varchar(32) CHARACTER SET latin1 NOT NULL, PRIMARY KEY (`diskio_id`), KEY `device_id` (`device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `username` char(30) NOT NULL, `password` varchar(34) DEFAULT NULL, `realname` varchar(64) NOT NULL, `email` varchar(64) NOT NULL, `descr` char(30) NOT NULL, `level` tinyint(4) NOT NULL DEFAULT '0', `can_modify_passwd` tinyint(4) NOT NULL DEFAULT '1', PRIMARY KEY (`user_id`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `username` char(30) NOT NULL, `password` varchar(34) DEFAULT NULL, `realname` varchar(64) NOT NULL, `email` varchar(64) NOT NULL, `descr` varchar(200) DEFAULT NULL, `level` tinyint(4) NOT NULL DEFAULT '0', `can_modify_passwd` tinyint(4) NOT NULL DEFAULT '1', PRIMARY KEY (`user_id`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `users_prefs` ( `user_id` int(16) NOT NULL, `pref` varchar(32) NOT NULL, `value` varchar(128) NOT NULL, PRIMARY KEY (`user_id`), UNIQUE KEY `user_id.pref` (`user_id`,`pref`), KEY `pref` (`pref`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `vlans` ( `vlan_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) DEFAULT NULL, `vlan_vlan` int(11) DEFAULT NULL, `vlan_domain` text, `vlan_descr` text, PRIMARY KEY (`vlan_id`), KEY `device_id` (`device_id`,`vlan_vlan`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `vminfo` ( `id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `vm_type` varchar(16) NOT NULL DEFAULT 'vmware', `vmwVmVMID` int(11) NOT NULL, `vmwVmDisplayName` varchar(128) NOT NULL, `vmwVmGuestOS` varchar(128) NOT NULL, `vmwVmMemSize` int(11) NOT NULL, `vmwVmCpus` int(11) NOT NULL, `vmwVmState` varchar(128) NOT NULL, PRIMARY KEY (`id`), KEY `device_id` (`device_id`), KEY `vmwVmVMID` (`vmwVmVMID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/html/includes/authentication/mysql.inc.php b/html/includes/authentication/mysql.inc.php index 151830d702..cf91f27c2d 100644 --- a/html/includes/authentication/mysql.inc.php +++ b/html/includes/authentication/mysql.inc.php @@ -100,13 +100,13 @@ function auth_usermanagement() return 1; } -function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd='1') +function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd=1, $description ="", $twofactor=0) { if (!user_exists($username)) { $hasher = new PasswordHash(8, FALSE); $encrypted = $hasher->HashPassword($password); - return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd), 'users'); + return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users'); } else { return FALSE; } @@ -114,7 +114,8 @@ function adduser($username, $password, $level, $email = "", $realname = "", $can function user_exists($username) { - return @dbFetchCell("SELECT COUNT(*) FROM users WHERE username = ?", array($username)); + $return = @dbFetchCell("SELECT COUNT(*) FROM users WHERE username = ?", array($username)); + return $return; } function get_userlevel($username) From 357af3265421a235c23272971b326df613480f21 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 10:19:09 -0700 Subject: [PATCH 03/22] Fixed UpadteDB function. It didn't seem to work. I fixed the syntax and hopefullt this won't break other things, but I guess as I test I'll find out. --- includes/dbFacile.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/dbFacile.php b/includes/dbFacile.php index 1f18c1a6fd..1ff1732f0c 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -24,10 +24,10 @@ Usage function dbQuery($sql, $parameters = array()) { global $fullSql, $debug; $fullSql = dbMakeQuery($sql, $parameters); - if($debug) { - print Console_Color::convert("\nSQL[%y".$fullSql."%n] "); - #echo("\nSQL[".$fullSql."] "); - } + //if($debug) { + //print Console_Color::convert("\nSQL[%y".$fullSql."%n] "); + //echo("\nSQL[".$fullSql."] "); + //} /* if($this->logFile) @@ -35,6 +35,10 @@ function dbQuery($sql, $parameters = array()) { */ $result = mysql_query($fullSql); // sets $this->result + if (!empty(mysql_error())) { + echo("\nSQL[".$fullSql."] "); + print mysql_error(); + } /* if($this->logFile) { $time_end = microtime(true); @@ -114,9 +118,9 @@ function dbUpdate($data, $table, $where = null, $parameters = array()) { // need field name and placeholder value // but how merge these field placeholders with actual $parameters array for the WHERE clause - $sql = 'UPDATE `' . $table . '` set '; + $sql = 'UPDATE `' . $table . '` SET '; foreach($data as $key => $value) { - $sql .= "`".$key."` ". '=:' . $key . ','; + $sql .= "`".$key."` = '" . $value . "',"; } $sql = substr($sql, 0, -1); // strip off last comma From b73f642bc65579d4b78cf0938a75853eadfdaa85 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 10:50:22 -0700 Subject: [PATCH 04/22] Fixed vlan discover so there isn't any more SQL errors. Will need further testing. --- includes/discovery/vlans.inc.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/discovery/vlans.inc.php b/includes/discovery/vlans.inc.php index 4d32f510c9..4342899ec7 100644 --- a/includes/discovery/vlans.inc.php +++ b/includes/discovery/vlans.inc.php @@ -55,16 +55,16 @@ foreach ($device['vlans'] as $domain_id => $vlans) 'port_id' => $port['port_id'], 'vlan' => $vlan_id); - $db_a = array('baseport' => $vlan_port_id, - 'priority' => $vlan_port['dot1dStpPortPriority'], - 'state' => $vlan_port['dot1dStpPortState'], - 'cost' => $vlan_port['dot1dStpPortPathCost']); + $db_a['baseport'] = $vlan_port_id; + $db_a['priority'] = isset($vlan_port['dot1dStpPortPriority']) ? $vlan_port['dot1dStpPortPriority'] : 0; + $db_a['state'] = isset($vlan_port['dot1dStpPortState']) ? $vlan_port['dot1dStpPortState'] : "unknown"; + $db_a['cost'] = isset($vlan_port['dot1dStpPortPathCost']) ? $vlan_port['dot1dStpPortPathCost'] : 0; $from_db = dbFetchRow("SELECT * FROM `ports_vlans` WHERE device_id = ? AND port_id = ? AND `vlan` = ?", array($device['device_id'], $port['port_id'], $vlan_id)); - + if ($from_db['port_vlan_id']) { - dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ?", $from_db['port_vlan_id']); + dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ". $from_db['port_vlan_id']); echo("Updated"); } else { dbInsert(array_merge($db_w, $db_a), 'ports_vlans'); From f70989542b47d2e814291bee7189f80c39cf04c3 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 12:08:26 -0700 Subject: [PATCH 05/22] Fixed entity-physical. Fixed the ifindex logic. Also fixed the update and insert function calls. --- includes/discovery/entity-physical.inc.php | 60 +++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/includes/discovery/entity-physical.inc.php b/includes/discovery/entity-physical.inc.php index 1f32288f21..e60e50514e 100755 --- a/includes/discovery/entity-physical.inc.php +++ b/includes/discovery/entity-physical.inc.php @@ -13,7 +13,7 @@ $entity_array = snmpwalk_cache_twopart_oid($device, "entAliasMappingIdentifier", $entity_array, "ENTITY-MIB:IF-MIB"); foreach ($entity_array as $entPhysicalIndex => $entry) { - + $entPhysicalDescr = $entry['entPhysicalDescr']; $entPhysicalContainedIn = $entry['entPhysicalContainedIn']; $entPhysicalClass = $entry['entPhysicalClass']; @@ -30,10 +30,16 @@ $entPhysicalAlias = $entry['entPhysicalAlias']; $entPhysicalAssetID = $entry['entPhysicalAssetID']; - if (isset($entity_array['$entPhysicalIndex']['0']['entAliasMappingIdentifier'])) { $ifIndex = $entity_array['$entPhysicalIndex']['0']['entAliasMappingIdentifier']; } + if (isset($entity_array[$entPhysicalIndex]['0']['entAliasMappingIdentifier'])) { + $ifIndex = $entity_array[$entPhysicalIndex]['0']['entAliasMappingIdentifier']; + } - if (!strpos($ifIndex, "fIndex") || $ifIndex == "") { unset($ifIndex); } - list(,$ifIndex) = explode(".", $ifIndex); + if (!strpos($ifIndex, "fIndex") || $ifIndex == "") { + unset($ifIndex); + } else { + $ifIndex_array = explode(".", $ifIndex); + $ifIndex = $ifIndex_array[1]; + } if ($entPhysicalVendorTypes[$entPhysicalVendorType] && !$entPhysicalModelName) { @@ -47,10 +53,52 @@ $entPhysical_id = dbFetchCell("SELECT entPhysical_id FROM `entPhysical` WHERE device_id = ? AND entPhysicalIndex = ?",array($device['device_id'], $entPhysicalIndex)); if ($entPhysical_id) { - dbUpdate(array('entPhysicalIndex' => $entPhysicalIndex, 'entPhysicalDescr' => $entPhysicalDescr, 'entPhysicalClass' => $entPhysicalClass, 'entPhysicalName' => $entPhysicalName, 'entPhysicalModelName' => $entPhysicalModelName, 'entPhysicalSerialNum' => $entPhysicalSerialNum, 'entPhysicalContainedIn' => $entPhysicalContainedIn, 'entPhysicalMfgName' => $entPhysicalMfgName, 'entPhysicalParentRelPos' => $entPhysicalParentRelPos, 'entPhysicalVendorType' => $entPhysicalVendorType, 'entPhysicalHardwareRev' => $entPhysicalHardwareRev, 'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev, 'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev, 'entPhysicalIsFRU' => $entPhysicalIsFRU, 'entPhysicalAlias' => $entPhysicalAlias, 'entPhysicalAssetID' => $entPhysicalAssetID), 'entPhysical', 'device_id=? AND entPhysicalIndex=?',array($device['device_id'],$entPhysicalIndex)); + $update_data = array( + 'entPhysicalIndex' => $entPhysicalIndex, + 'entPhysicalDescr' => $entPhysicalDescr, + 'entPhysicalClass' => $entPhysicalClass, + 'entPhysicalName' => $entPhysicalName, + 'entPhysicalModelName' => $entPhysicalModelName, + 'entPhysicalSerialNum' => $entPhysicalSerialNum, + 'entPhysicalContainedIn' => $entPhysicalContainedIn, + 'entPhysicalMfgName' => $entPhysicalMfgName, + 'entPhysicalParentRelPos' => $entPhysicalParentRelPos, + 'entPhysicalVendorType' => $entPhysicalVendorType, + 'entPhysicalHardwareRev' => $entPhysicalHardwareRev, + 'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev, + 'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev, + 'entPhysicalIsFRU' => $entPhysicalIsFRU, + 'entPhysicalAlias' => $entPhysicalAlias, + 'entPhysicalAssetID' => $entPhysicalAssetID + ); + dbUpdate($update_data, 'entPhysical', 'device_id=? AND entPhysicalIndex=?',array($device['device_id'],$entPhysicalIndex)); echo("."); } else { - dbInsert(array('device_id' => $device['device_id'], 'entPhysicalIndex' => $entPhysicalIndex, 'entPhysicalDescr' => $entPhysicalDescr,'entPhysicalClass' => $entPhysicalClass, 'entPhysicalName' => $entPhysicalName, 'entPhysicalModelName' => $entPhysicalModelName, 'entPhysicalSerialNum' => $entPhysicalSerialNum, 'entPhysicalContainedIn' => $entPhysicalContainedIn, 'entPhysicalMfgName' => $entPhysicalMfgName, 'entPhysicalParentRelPos' => $entPhysicalParentRelPos, 'entPhysicalVendorType' => $entPhysicalVendorType, 'entPhysicalHardwareRev' => $entPhysicalHardwareRev, 'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev, 'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev, 'entPhysicalIsFRU' => $entPhysicalIsFRU, 'entPhysicalAlias' => $entPhysicalAlias, 'entPhysicalAssetID' => $entPhysicalAssetID, 'ifIndex' => $ifIndex), 'entPhysical'); + $insert_data = array( + 'device_id' => $device['device_id'], + 'entPhysicalIndex' => $entPhysicalIndex, + 'entPhysicalDescr' => $entPhysicalDescr, + 'entPhysicalClass' => $entPhysicalClass, + 'entPhysicalName' => $entPhysicalName, + 'entPhysicalModelName' => $entPhysicalModelName, + 'entPhysicalSerialNum' => $entPhysicalSerialNum, + 'entPhysicalContainedIn' => $entPhysicalContainedIn, + 'entPhysicalMfgName' => $entPhysicalMfgName, + 'entPhysicalParentRelPos' => $entPhysicalParentRelPos, + 'entPhysicalVendorType' => $entPhysicalVendorType, + 'entPhysicalHardwareRev' => $entPhysicalHardwareRev, + 'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev, + 'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev, + 'entPhysicalIsFRU' => $entPhysicalIsFRU, + 'entPhysicalAlias' => $entPhysicalAlias, + 'entPhysicalAssetID' => $entPhysicalAssetID + ); + + if (!empty($ifIndex)) { + $insert_data['ifIndex'] = $ifIndex; + } + + dbInsert($insert_data, 'entPhysical'); echo("+"); } From 469a06ae93f6a35dfdcde5436e12908575abc6a6 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 14:14:49 -0700 Subject: [PATCH 06/22] Fixed processor discovery. SQL correctly inserts and updates now. Also fixed usage field for cisco devices. --- includes/discovery/functions.inc.php | 30 ++++++++++++++++++++--- includes/discovery/processors/ios.inc.php | 4 ++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 103a7eebe8..166b7f89e0 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -428,20 +428,44 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec { global $config, $debug; - if ($debug) { echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); } + if ($debug) { + echo("\n"); + var_dump($device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex); + } + if ($descr) { $descr = trim(str_replace("\"", "", $descr)); if (dbFetchCell("SELECT COUNT(processor_id) FROM `processors` WHERE `processor_index` = ? AND `device_id` = ? AND `processor_type` = ?",array($index,$device['device_id'], $type)) == '0') { - $inserted = dbInsert(array('entPhysicalIndex' => $entPhysicalIndex, 'hrDeviceIndex' => $hrDeviceIndex, 'device_id' => $device['device_id'],'processor_descr' => $descr, 'processor_index' => $index, 'processor_oid' => $oid, 'processor_usage' => $current, 'processor_type' => $type, 'processor_precision' => $precision), 'processors'); + $insert_data = array( + 'entPhysicalIndex' => $entPhysicalIndex, + 'device_id' => $device['device_id'], + 'processor_descr' => $descr, + 'processor_index' => $index, + 'processor_oid' => $oid, + 'processor_usage' => $current, + 'processor_type' => $type, + 'processor_precision' => $precision + ); + if (!empty($hrDeviceIndex)) { + $insert_data['hrDeviceIndex'] = $hrDeviceIndex; + } + + $inserted = dbInsert($insert_data, 'processors'); echo("+"); log_event("Processor added: type ".mres($type)." index ".mres($index)." descr ". mres($descr), $device, 'processor', $inserted); } else { echo("."); - dbUpdate(array('processor_descr' => $descr, 'processor_oid' => $oid, 'processor_precision' => $precision), 'processors', '`device_id`=? AND `processor_index`=? AND `processor_type`=?',array($device['device_id'],$index,$type)); + $update_data = array( + 'processor_descr' => $descr, + 'processor_oid' => $oid, + 'processor_usage' => $current, + 'processor_precision' => $precision + ); + dbUpdate($update_data, 'processors', '`device_id`=? AND `processor_index`=? AND `processor_type`=?',array($device['device_id'],$index,$type)); if ($debug) { print $query . "\n"; } } $valid[$type][$index] = 1; diff --git a/includes/discovery/processors/ios.inc.php b/includes/discovery/processors/ios.inc.php index b186b602de..71c98b67ff 100755 --- a/includes/discovery/processors/ios.inc.php +++ b/includes/discovery/processors/ios.inc.php @@ -39,7 +39,8 @@ if ($device['os_group'] == "cisco" || $device['os'] == "acsw") if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "") { - discover_processor($valid['processor'], $device, $usage_oid, $index, "cpm", $descr, "1", $entry['juniSystemModuleCpuUtilPct'], $entPhysicalIndex, NULL); + //discover_processor($valid['processor'], $device, $usage_oid, $index, "cpm", $descr, "1", $entry['juniSystemModuleCpuUtilPct'], $entPhysicalIndex, NULL); + discover_processor($valid['processor'], $device, $usage_oid, $index, "cpm", $descr, "1", $usage, $entPhysicalIndex, NULL); } } } @@ -47,6 +48,7 @@ if ($device['os_group'] == "cisco" || $device['os'] == "acsw") if (!is_array($valid['processor']['cpm'])) { $avgBusy5 = snmp_get($device, ".1.3.6.1.4.1.9.2.1.58.0", "-Oqv"); + if (is_numeric($avgBusy5)) { discover_processor($valid['processor'], $device, ".1.3.6.1.4.1.9.2.1.58.0", "0", "ios", "Processor", "1", $avgBusy5, NULL, NULL); From d47952f69eafdf44b115a315f04c9dcc87ce81b0 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 14:52:04 -0700 Subject: [PATCH 07/22] Fixed mempools function. --- includes/discovery/functions.inc.php | 43 +++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 166b7f89e0..b6f2c02dab 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -475,20 +475,55 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = "1", $entPhysicalIndex = NULL, $hrDeviceIndex = NULL) { global $config, $debug; - - if ($debug) { echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); } + + if ($debug) { + echo("\n"); + var_dump($device, $index, $type, $descr, $precision, $entPhysicalIndex, $hrDeviceIndex); + } + + #FIXME implement the mempool_perc, mempool_used, etc. if ($descr) { if (dbFetchCell("SELECT COUNT(mempool_id) FROM `mempools` WHERE `mempool_index` = ? AND `device_id` = ? AND `mempool_type` = ?",array($index,$device['device_id'], $type)) == '0') { - $inserted = dbInsert(array('entPhysicalIndex' => $entPhysicalIndex, 'hrDeviceIndex' => $hrDeviceIndex, 'device_id' => $device['device_id'],'mempool_descr' => $descr, 'mempool_index' => $index, 'mempool_type' => $type, 'mempool_precision' => $precision), 'mempools'); + $insert_data = array( + 'device_id' => $device['device_id'], + 'mempool_descr' => $descr, + 'mempool_index' => $index, + 'mempool_type' => $type, + 'mempool_precision' => $precision, + 'mempool_perc' => 0, + 'mempool_used' => 0, + 'mempool_free' => 0, + 'mempool_total' => 0 + ); + + if (!empty($entPhysicalIndex)) { + $insert_data['entPhysicalIndex'] = $entPhysicalIndex; + } + + if (!empty($hrDeviceIndex)) { + $insert_data['hrDeviceIndex'] = $hrDeviceIndex; + } + + $inserted = dbInsert($insert_data, 'mempools'); echo("+"); log_event("Memory pool added: type ".mres($type)." index ".mres($index)." descr ". mres($descr), $device, 'mempool', $inserted); } else { echo("."); - dbUpdate(array('mempool_descr' => $descr, 'entPhysicalIndex' => $entPhysicalIndex, 'hrDeviceIndex' => $hrDeviceIndex), 'mempools', 'device_id=? AND mempool_index=? AND mempool_type',array($device['device_id'],$index,$type)); + $update_data['mempool_descr'] = $descr; + + if (!empty($entPhysicalIndex)) { + $update_data['entPhysicalIndex'] = $entPhysicalIndex; + } + + if (!empty($hrDeviceIndex)) { + $update_data['hrDeviceIndex'] = $hrDeviceIndex; + } + + dbUpdate($update_data, 'mempools', 'device_id=? AND mempool_index=? AND mempool_type=?',array($device['device_id'],$index,$type)); if ($debug) { print $query . "\n"; } } $valid[$type][$index] = 1; From 03ad4b7bc5af3db0c579bb7c881497b48651fb09 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 15:24:29 -0700 Subject: [PATCH 08/22] Fixed SQL statement so things don't go broke. --- includes/discovery/temperatures/cisco-envmon.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/temperatures/cisco-envmon.inc.php b/includes/discovery/temperatures/cisco-envmon.inc.php index 9de2ad8a8f..df23e9a1a6 100644 --- a/includes/discovery/temperatures/cisco-envmon.inc.php +++ b/includes/discovery/temperatures/cisco-envmon.inc.php @@ -2,7 +2,7 @@ // FIXME - dbFacile and fewer SNMP_GETs -if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `sensor_class` = 'temperature' AND (`sensor_type` = 'cisco-entity-sensor' OR `sensor_type` = 'entity-sensor'",array($device['device_id'])) == "0" && ($device['os_group'] == "cisco")) +if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `sensor_class` = 'temperature' AND (`sensor_type` = 'cisco-entity-sensor' OR `sensor_type` = 'entity-sensor')",array($device['device_id'])) == "0" && ($device['os_group'] == "cisco")) { echo("CISCO-ENVMON-MIB: "); $oids = snmp_walk($device, ".1.3.6.1.4.1.9.9.13.1.3.1.2", "-Osqn", "CISCO-ENVMON-MIB"); From c2ab3e1d0d0c4c8db63cc7a5ed24b07c94efc2b8 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 15:37:51 -0700 Subject: [PATCH 09/22] Fixed the discover_links function so that it can not blow up with NULL values. --- includes/discovery/functions.inc.php | 37 +++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index b6f2c02dab..c99a2dfe0f 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -132,7 +132,7 @@ function discover_device($device, $options = NULL) function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = NULL, $low_warn_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL, $poller_type = 'snmp', $entPhysicalIndex = NULL, $entPhysicalIndex_measured = NULL) { global $config, $debug; - + if ($debug) { echo("Discover sensor: $oid, $index, $type, $descr, $poller_type, $precision, $entPhysicalIndex\n"); } if (is_null($low_warn_limit) || !is_null($warn_limit)) @@ -334,7 +334,7 @@ function sensor_limit($class, $current) function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp') { $entries = dbFetchRows("SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?", array($class, $device['device_id'], $poller_type)); - + if (count($entries)) { foreach ($entries as $entry) @@ -374,13 +374,29 @@ function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr) function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version) { global $config, $debug, $link_exists; - + + if ($debug) { + echo("\n"); + var_dump($local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version); + } + if (dbFetchCell("SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?", array($remote_hostname, $local_port_id, $protocol, $remote_port)) == "0") { + $insert_data = array( + 'local_port_id' => $local_port_id, + 'protocol' => $protocol, + 'remote_hostname' => $remote_hostname, + 'remote_port' => $remote_port, + 'remote_platform' => $remote_platform, + 'remote_version' => $remote_version + ); + + if (!empty($remote_port_id)) { + $insert_data['remote_port_id'] = $remote_port_id; + } - $inserted = dbInsert(array('local_port_id' => $local_port_id,'protocol' => $protocol,'remote_port_id' => $remote_port_id,'remote_hostname' => $remote_hostname, - 'remote_port' => $remote_port,'remote_platform' => $remote_platform,'remote_version' => $remote_version), 'links'); + $inserted = dbInsert($insert_data, 'links'); echo("+"); if ($debug) { echo("( $inserted inserted )"); } } @@ -393,7 +409,16 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn } else { - $updated = dbUpdate(array('remote_port_id' => $remote_port_id, 'remote_platform' => $remote_platform, 'remote_version' => $remote_version), 'links', '`id` = ?', array($data['id'])); + $update_data = array( + 'remote_platform' => $remote_platform, + 'remote_version' => $remote_version + ); + + if (!empty($remote_port_id)) { + $update_data['remote_port_id'] = $remote_port_id; + } + + $updated = dbUpdate($update_data, 'links', '`id` = ?', array($data['id'])); echo("U"); if ($debug) { echo("( $updated updated )"); } } } From 4781e6d05eaca811e8709671832eebd0fc4fc979 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 16:06:32 -0700 Subject: [PATCH 10/22] Fixed the discovered_last field update thing. --- includes/dbFacile.php | 6 +++++- includes/discovery/functions.inc.php | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/dbFacile.php b/includes/dbFacile.php index 1ff1732f0c..e85df8a1c3 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -120,7 +120,11 @@ function dbUpdate($data, $table, $where = null, $parameters = array()) { // but how merge these field placeholders with actual $parameters array for the WHERE clause $sql = 'UPDATE `' . $table . '` SET '; foreach($data as $key => $value) { - $sql .= "`".$key."` = '" . $value . "',"; + if ($value == "NOW()") { + $sql .= "`".$key."` = " . $value . ","; + } else { + $sql .= "`".$key."` = '" . $value . "',"; + } } $sql = substr($sql, 0, -1); // strip off last comma diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index c99a2dfe0f..d22084ccf8 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -118,8 +118,8 @@ function discover_device($device, $options = NULL) } $device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5); - - dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id'])); + + dbUpdate(array('last_discovered' => 'NOW()', 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id'])); echo("Discovered in $device_time seconds\n"); From d7ea7e71bf529b344529bdf4cb1700960138734d Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 16:19:14 -0700 Subject: [PATCH 11/22] Fixed polling mempool thing so that NULL values don't break things. --- includes/polling/mempools.inc.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/polling/mempools.inc.php b/includes/polling/mempools.inc.php index bc167dcae0..2d065afe11 100755 --- a/includes/polling/mempools.inc.php +++ b/includes/polling/mempools.inc.php @@ -31,8 +31,20 @@ foreach (dbFetchRows("SELECT * FROM mempools WHERE device_id = ?", array($device } rrdtool_update($mempool_rrd,"N:".$mempool['used'].":".$mempool['free']); - $mempool['state'] = array('mempool_used' => $mempool['used'], 'mempool_perc' => $percent, 'mempool_free' => $mempool['free'], - 'mempool_total' => $mempool['total'], 'mempool_largestfree' => $mempool['largestfree'], 'mempool_lowestfree' => $mempool['lowestfree']); + $mempool['state'] = array( + 'mempool_used' => $mempool['used'], + 'mempool_perc' => $percent, + 'mempool_free' => $mempool['free'], + 'mempool_total' => $mempool['total'] + ); + + if (!empty($mempool['largestfree'])) { + $mempool['state']['mempool_largestfree'] = $mempool['largestfree']; + } + + if (!empty($mempool['lowestfree'])) { + $mempool['state']['mempool_lowestfree'] = $mempool['lowestfree']; + } if ($config['memcached']['enable']) { From 87bd0da996f45ac1b4a9bfdc824f78a2039d8464 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Mon, 16 Feb 2015 16:33:56 -0700 Subject: [PATCH 12/22] Fixed polling ports so that NULL values don't break stuff. Basically I just have a foreach loop to unset any NULL values. Also fixed the NOW() SQL statements at the end of polling. --- includes/polling/functions.inc.php | 4 ++-- includes/polling/ports.inc.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 4582426c43..b40a5f18a9 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -223,9 +223,9 @@ function poll_device($device, $options) rrdtool_update($ping_rrd, "N:$ping_time"); } - $update_array['last_polled'] = array('NOW()'); + $update_array['last_polled'] = 'NOW()'; $update_array['last_polled_timetaken'] = $device_time; - $update_array['last_ping'] = array('NOW()'); + $update_array['last_ping'] = 'NOW()'; $update_array['last_ping_timetaken'] = $ping_time; #echo("$device_end - $device_start; $device_time $device_run"); diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index c8a18e885f..6c43bf507a 100755 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -430,6 +430,12 @@ foreach ($ports as $port) $memcache->set('port-'.$port['port_id'].'-state', $port['state']); } + foreach ($port['update'] as $key => $val_check){ + if (!isset($val_check)) { + unset($port['update'][$key]); + } + } + // Update Database if (count($port['update'])) { From 7996686e53876b52b790b8218c9df280506f2ad8 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Tue, 17 Feb 2015 15:31:02 -0700 Subject: [PATCH 13/22] Fixed SQL error relating to the temperature in the cisco-envmon.inc.php in discovery. --- includes/discovery/temperatures/cisco-envmon.inc.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/discovery/temperatures/cisco-envmon.inc.php b/includes/discovery/temperatures/cisco-envmon.inc.php index df23e9a1a6..923fa75563 100644 --- a/includes/discovery/temperatures/cisco-envmon.inc.php +++ b/includes/discovery/temperatures/cisco-envmon.inc.php @@ -24,8 +24,9 @@ if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `senso $descr = str_replace("temperature", "", $descr); $descr = str_replace("temperature", "", $descr); $descr = trim($descr); - - discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, 'cisco', $descr, '1', '1', NULL, NULL, NULL, NULL, $temperature); + + + discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, 'cisco', $descr, '1', '1', NULL, NULL, NULL, NULL, stristr($temperature, " degrees", true)); } } } From dd553342939e06aa57f1138c81ccc62cef436988 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Wed, 18 Feb 2015 08:35:02 -0700 Subject: [PATCH 14/22] Rethought this code. Added some logic to detect a temperature value that contains more than numbers. --- includes/discovery/temperatures/cisco-envmon.inc.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/discovery/temperatures/cisco-envmon.inc.php b/includes/discovery/temperatures/cisco-envmon.inc.php index 923fa75563..c0224d49b8 100644 --- a/includes/discovery/temperatures/cisco-envmon.inc.php +++ b/includes/discovery/temperatures/cisco-envmon.inc.php @@ -25,8 +25,11 @@ if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `senso $descr = str_replace("temperature", "", $descr); $descr = trim($descr); - - discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, 'cisco', $descr, '1', '1', NULL, NULL, NULL, NULL, stristr($temperature, " degrees", true)); + if (!is_numeric($temperature)) { + $temperature = stristr($temperature, " degrees", true); + } + + discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, 'cisco', $descr, '1', '1', NULL, NULL, NULL, NULL, $temperature); } } } From af291f4fc7c2cfb606d9df89a4f8b75c4eeed2bb Mon Sep 17 00:00:00 2001 From: mchasteen Date: Wed, 18 Feb 2015 08:36:57 -0700 Subject: [PATCH 15/22] Added some logic to keep a mac address that has no associated port from being added to the ipv4_mac table. I found that a cisco device was trying to add a loop-back mac address (000000000000). --- includes/discovery/arp-table.inc.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index bd20dd5a50..919e963c12 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -43,11 +43,17 @@ foreach (explode("\n", $ipNetToMedia_data) as $data) dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?',array($interface['port_id'],$ip)); echo("."); } - else + elseif (isset($interface['port_id'])) { echo("+"); #echo("Add MAC $mac\n"); - dbInsert(array('port_id' => $interface['port_id'], 'mac_address' => $clean_mac, 'ipv4_address' => $ip), 'ipv4_mac'); + $insert_data = array( + 'port_id' => $interface['port_id'], + 'mac_address' => $clean_mac, + 'ipv4_address' => $ip + ); + + dbInsert($insert_data, 'ipv4_mac'); } } } From 9d3b866202234a35817a6a9a72047f7a00d1d368 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Wed, 18 Feb 2015 08:39:05 -0700 Subject: [PATCH 16/22] This probably should have been commited earlier. Added some logic to remove NULL values from sensor DB inserts. --- includes/discovery/functions.inc.php | 29 ++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index d22084ccf8..a825356ff1 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -85,7 +85,7 @@ function discover_device($device, $options = NULL) } echo("\n"); - + // If we've specified a module, use that, else walk the modules array if ($options['m']) { @@ -158,9 +158,30 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, list($high_limit, $low_limit) = array($low_limit, $high_limit); } - $insert = array('poller_type' => $poller_type, 'sensor_class' => $class, 'device_id' => $device['device_id'], 'sensor_oid' => $oid, 'sensor_index' => $index, 'sensor_type' => $type, 'sensor_descr' => $descr, - 'sensor_divisor' => $divisor, 'sensor_multiplier' => $multiplier, 'sensor_limit' => $high_limit, 'sensor_limit_warn' => $warn_limit, 'sensor_limit_low' => $low_limit, - 'sensor_limit_low_warn' => $low_warn_limit, 'sensor_current' => $current, 'entPhysicalIndex' => $entPhysicalIndex, 'entPhysicalIndex_measured' => $entPhysicalIndex_measured ); + $insert = array( + 'poller_type' => $poller_type, + 'sensor_class' => $class, + 'device_id' => $device['device_id'], + 'sensor_oid' => $oid, + 'sensor_index' => $index, + 'sensor_type' => $type, + 'sensor_descr' => $descr, + 'sensor_divisor' => $divisor, + 'sensor_multiplier' => $multiplier, + 'sensor_limit' => $high_limit, + 'sensor_limit_warn' => $warn_limit, + 'sensor_limit_low' => $low_limit, + 'sensor_limit_low_warn' => $low_warn_limit, + 'sensor_current' => $current, + 'entPhysicalIndex' => $entPhysicalIndex, + 'entPhysicalIndex_measured' => $entPhysicalIndex_measured + ); + + foreach ($insert as $key => $val_check){ + if (!isset($val_check)) { + unset($insert[$key]); + } + } $inserted = dbInsert($insert, 'sensors'); From 984e4a8cabb11233df1c1cfc1aa870f78d702d94 Mon Sep 17 00:00:00 2001 From: mchasteen Date: Wed, 18 Feb 2015 10:54:02 -0700 Subject: [PATCH 17/22] Fixed the global alert_rull add SQL. Added a default value for disabled (set to 0). This could probably be fixed in the schema if the default value is set. --- html/includes/print-alert-rules.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/html/includes/print-alert-rules.php b/html/includes/print-alert-rules.php index 8c6f144d35..9eb19a10c5 100644 --- a/html/includes/print-alert-rules.php +++ b/html/includes/print-alert-rules.php @@ -6,14 +6,14 @@ '-1', 'rule' => '%devices.status != "1" && %devices.disabled = "0" && %devices.ignore = "0"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'name' => 'Devices up/down'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%devices.uptime < "300" && %devices.disabled = "0" && %devices.ignore = "0"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'name' => 'Device rebooted'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerState != "established"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'name' => 'BGP Session down'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerFsmEstablishedTime < "300" && %bgpPeers.bgpPeerState = "established"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'name' => 'BGP Session establised'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%ports.ifOperStatus != "up" && %ports.ifAdminStatus = "up" && %ports.deleted = "0" && %ports.ignore = "0" && %ports.disabled = "0"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'name' => 'Port status up/down'); - $default_rules[] = array('device_id' => '-1', 'rule' => '((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100 >= 80', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'name' => 'Port utilisation over threshold'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current > %sensors.sensor_limit', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'name' => 'Sensor over limit'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current < %sensors.sensor_limit_low', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'name' => 'Sensor under limit'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%devices.status != "1" && %devices.disabled = "0" && %devices.ignore = "0"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Devices up/down'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%devices.uptime < "300" && %devices.disabled = "0" && %devices.ignore = "0"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'Device rebooted'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerState != "established"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'BGP Session down'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerFsmEstablishedTime < "300" && %bgpPeers.bgpPeerState = "established"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'BGP Session establised'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%ports.ifOperStatus != "up" && %ports.ifAdminStatus = "up" && %ports.deleted = "0" && %ports.ignore = "0" && %ports.disabled = "0"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'Port status up/down'); + $default_rules[] = array('device_id' => '-1', 'rule' => '((%ports.ifInOctets_rate*8)/%ports.ifSpeed)*100 >= 80', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Port utilisation over threshold'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current > %sensors.sensor_limit', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Sensor over limit'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current < %sensors.sensor_limit_low', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Sensor under limit'); foreach( $default_rules as $add_rule ) { dbInsert($add_rule,'alert_rules'); } From e0fbcb9268d7903f26d741fb3435f496f6175822 Mon Sep 17 00:00:00 2001 From: laf Date: Wed, 18 Feb 2015 20:08:43 +0000 Subject: [PATCH 18/22] test --- includes/dbFacile.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/dbFacile.php b/includes/dbFacile.php index e85df8a1c3..c3aa8ed6bc 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -35,10 +35,13 @@ function dbQuery($sql, $parameters = array()) { */ $result = mysql_query($fullSql); // sets $this->result - if (!empty(mysql_error())) { + if (mysql_error()) { echo("\nSQL[".$fullSql."] "); print mysql_error(); } + if(mysql_error()) { + file_put_contents('/tmp/mysql_strict.log',date("Y-m-d H:i:s").','.$fullSql.','.mysql_error()."\n",FILE_APPEND); + } /* if($this->logFile) { $time_end = microtime(true); From 15cc00c27de28fdf6da6faaab4388a8c7bb39e19 Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 26 Feb 2015 21:51:28 +0000 Subject: [PATCH 19/22] Tidying up --- includes/dbFacile.php | 23 ++++++----------------- includes/discovery/functions.inc.php | 10 ++++------ includes/discovery/processors/ios.inc.php | 2 -- includes/discovery/vlans.inc.php | 2 +- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/includes/dbFacile.php b/includes/dbFacile.php index c3aa8ed6bc..1f18c1a6fd 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -24,10 +24,10 @@ Usage function dbQuery($sql, $parameters = array()) { global $fullSql, $debug; $fullSql = dbMakeQuery($sql, $parameters); - //if($debug) { - //print Console_Color::convert("\nSQL[%y".$fullSql."%n] "); - //echo("\nSQL[".$fullSql."] "); - //} + if($debug) { + print Console_Color::convert("\nSQL[%y".$fullSql."%n] "); + #echo("\nSQL[".$fullSql."] "); + } /* if($this->logFile) @@ -35,13 +35,6 @@ function dbQuery($sql, $parameters = array()) { */ $result = mysql_query($fullSql); // sets $this->result - if (mysql_error()) { - echo("\nSQL[".$fullSql."] "); - print mysql_error(); - } - if(mysql_error()) { - file_put_contents('/tmp/mysql_strict.log',date("Y-m-d H:i:s").','.$fullSql.','.mysql_error()."\n",FILE_APPEND); - } /* if($this->logFile) { $time_end = microtime(true); @@ -121,13 +114,9 @@ function dbUpdate($data, $table, $where = null, $parameters = array()) { // need field name and placeholder value // but how merge these field placeholders with actual $parameters array for the WHERE clause - $sql = 'UPDATE `' . $table . '` SET '; + $sql = 'UPDATE `' . $table . '` set '; foreach($data as $key => $value) { - if ($value == "NOW()") { - $sql .= "`".$key."` = " . $value . ","; - } else { - $sql .= "`".$key."` = '" . $value . "',"; - } + $sql .= "`".$key."` ". '=:' . $key . ','; } $sql = substr($sql, 0, -1); // strip off last comma diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index a825356ff1..1b4db40c59 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -132,7 +132,7 @@ function discover_device($device, $options = NULL) function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = NULL, $low_warn_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL, $poller_type = 'snmp', $entPhysicalIndex = NULL, $entPhysicalIndex_measured = NULL) { global $config, $debug; - + if ($debug) { echo("Discover sensor: $oid, $index, $type, $descr, $poller_type, $precision, $entPhysicalIndex\n"); } if (is_null($low_warn_limit) || !is_null($warn_limit)) @@ -355,7 +355,7 @@ function sensor_limit($class, $current) function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp') { $entries = dbFetchRows("SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?", array($class, $device['device_id'], $poller_type)); - + if (count($entries)) { foreach ($entries as $entry) @@ -475,8 +475,7 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec global $config, $debug; if ($debug) { - echo("\n"); - var_dump($device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex); + echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); } if ($descr) @@ -523,8 +522,7 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = global $config, $debug; if ($debug) { - echo("\n"); - var_dump($device, $index, $type, $descr, $precision, $entPhysicalIndex, $hrDeviceIndex); + echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); } #FIXME implement the mempool_perc, mempool_used, etc. diff --git a/includes/discovery/processors/ios.inc.php b/includes/discovery/processors/ios.inc.php index 71c98b67ff..ce67bd11f0 100755 --- a/includes/discovery/processors/ios.inc.php +++ b/includes/discovery/processors/ios.inc.php @@ -39,7 +39,6 @@ if ($device['os_group'] == "cisco" || $device['os'] == "acsw") if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "") { - //discover_processor($valid['processor'], $device, $usage_oid, $index, "cpm", $descr, "1", $entry['juniSystemModuleCpuUtilPct'], $entPhysicalIndex, NULL); discover_processor($valid['processor'], $device, $usage_oid, $index, "cpm", $descr, "1", $usage, $entPhysicalIndex, NULL); } } @@ -48,7 +47,6 @@ if ($device['os_group'] == "cisco" || $device['os'] == "acsw") if (!is_array($valid['processor']['cpm'])) { $avgBusy5 = snmp_get($device, ".1.3.6.1.4.1.9.2.1.58.0", "-Oqv"); - if (is_numeric($avgBusy5)) { discover_processor($valid['processor'], $device, ".1.3.6.1.4.1.9.2.1.58.0", "0", "ios", "Processor", "1", $avgBusy5, NULL, NULL); diff --git a/includes/discovery/vlans.inc.php b/includes/discovery/vlans.inc.php index 4342899ec7..6ad9889850 100644 --- a/includes/discovery/vlans.inc.php +++ b/includes/discovery/vlans.inc.php @@ -64,7 +64,7 @@ foreach ($device['vlans'] as $domain_id => $vlans) if ($from_db['port_vlan_id']) { - dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ". $from_db['port_vlan_id']); + dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ?", array($from_db['port_vlan_id'])); echo("Updated"); } else { dbInsert(array_merge($db_w, $db_a), 'ports_vlans'); From ba5eb4e51aa5583b0dd192bb1618c136dd75a296 Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 26 Feb 2015 22:02:09 +0000 Subject: [PATCH 20/22] Tidying up --- includes/discovery/functions.inc.php | 6 +++--- includes/polling/functions.inc.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 1b4db40c59..d37c59fb6e 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -85,7 +85,7 @@ function discover_device($device, $options = NULL) } echo("\n"); - + // If we've specified a module, use that, else walk the modules array if ($options['m']) { @@ -118,8 +118,8 @@ function discover_device($device, $options = NULL) } $device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5); - - dbUpdate(array('last_discovered' => 'NOW()', 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id'])); + + dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id'])); echo("Discovered in $device_time seconds\n"); diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index b40a5f18a9..4582426c43 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -223,9 +223,9 @@ function poll_device($device, $options) rrdtool_update($ping_rrd, "N:$ping_time"); } - $update_array['last_polled'] = 'NOW()'; + $update_array['last_polled'] = array('NOW()'); $update_array['last_polled_timetaken'] = $device_time; - $update_array['last_ping'] = 'NOW()'; + $update_array['last_ping'] = array('NOW()'); $update_array['last_ping_timetaken'] = $ping_time; #echo("$device_end - $device_start; $device_time $device_run"); From e1b460320a10edf0db6ca2a64dda12103faa2dc7 Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 26 Feb 2015 22:12:26 +0000 Subject: [PATCH 21/22] Tidying up --- html/pages/device.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index 467778ab29..92d7a36a16 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -60,6 +60,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) $health = dbFetchCell("SELECT COUNT(*) FROM storage WHERE device_id = '" . $device['device_id'] . "'") + dbFetchCell("SELECT COUNT(sensor_id) FROM sensors WHERE device_id = '" . $device['device_id'] . "'") + + dbFetchCell("SELECT COUNT(*) FROM mempools WHERE device_id = '" . $device['device_id'] . "'") + dbFetchCell("SELECT COUNT(*) FROM processors WHERE device_id = '" . $device['device_id'] . "'"); if ($health) From 7f823b6d498a68ad725d5f381678c7fe37714f67 Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 1 Mar 2015 12:23:31 +0000 Subject: [PATCH 22/22] Adding more updates found by f0o --- includes/discovery/functions.inc.php | 4 +++- includes/discovery/hr-device.inc.php | 2 +- sql-schema/040.sql | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 sql-schema/040.sql diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index d37c59fb6e..a3a16c897f 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -484,7 +484,6 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec if (dbFetchCell("SELECT COUNT(processor_id) FROM `processors` WHERE `processor_index` = ? AND `device_id` = ? AND `processor_type` = ?",array($index,$device['device_id'], $type)) == '0') { $insert_data = array( - 'entPhysicalIndex' => $entPhysicalIndex, 'device_id' => $device['device_id'], 'processor_descr' => $descr, 'processor_index' => $index, @@ -496,6 +495,9 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec if (!empty($hrDeviceIndex)) { $insert_data['hrDeviceIndex'] = $hrDeviceIndex; } + if( !empty($entPhysicalIndex) ) { + $insert_data['entPhysicalIndex'] = $entPhysicalIndex; + } $inserted = dbInsert($insert_data, 'processors'); echo("+"); diff --git a/includes/discovery/hr-device.inc.php b/includes/discovery/hr-device.inc.php index b5e4d8a6a9..2f55b7f62e 100755 --- a/includes/discovery/hr-device.inc.php +++ b/includes/discovery/hr-device.inc.php @@ -31,7 +31,7 @@ if (is_array($hrDevices)) } else { - $inserted_rows = dbInsert(array('hrDeviceIndex' => mres($hrDevice['hrDeviceIndex']), 'device_id' => mres($device['device_id']), 'hrDeviceType' => mres($hrDevice['hrDeviceType']),'hrDeviceDescr' => mres($hrDevice['hrDeviceDescr']), 'hrDeviceStatus' => mres($hrDevice['hrDeviceStatus']), 'hrDeviceErrors' => mres($hrDevice['hrDeviceErrors'])), 'hrDevice'); + $inserted_rows = dbInsert(array('hrDeviceIndex' => mres($hrDevice['hrDeviceIndex']), 'device_id' => mres($device['device_id']), 'hrDeviceType' => mres($hrDevice['hrDeviceType']),'hrDeviceDescr' => mres($hrDevice['hrDeviceDescr']), 'hrDeviceStatus' => mres($hrDevice['hrDeviceStatus']), 'hrDeviceErrors' => (int) mres($hrDevice['hrDeviceErrors'])), 'hrDevice'); echo("+"); if ($debug) { print_r($hrDevice); echo("$inserted_rows row inserted"); } } diff --git a/sql-schema/040.sql b/sql-schema/040.sql new file mode 100644 index 0000000000..d3d954ff81 --- /dev/null +++ b/sql-schema/040.sql @@ -0,0 +1,8 @@ +ALTER TABLE `devices` CHANGE `agent_uptime` `agent_uptime` INT( 11 ) NOT NULL DEFAULT '0'; +ALTER TABLE `devices` CHANGE `type` `type` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''; +ALTER TABLE `ports` CHANGE `ifVrf` `ifVrf` INT( 11 ) NOT NULL DEFAULT '0'; +ALTER TABLE `storage` CHANGE `storage_free` `storage_free` BIGINT( 20 ) NOT NULL DEFAULT '0'; +ALTER TABLE `storage` CHANGE `storage_used` `storage_used` BIGINT( 20 ) NOT NULL DEFAULT '0'; +ALTER TABLE `storage` CHANGE `storage_perc` `storage_perc` INT NOT NULL DEFAULT '0'; +ALTER TABLE `processors` CHANGE `entPhysicalIndex` `entPhysicalIndex` INT( 11 ) NOT NULL DEFAULT '0'; +ALTER TABLE `hrDevice` CHANGE `hrDeviceErrors` `hrDeviceErrors` INT( 11 ) NOT NULL DEFAULT '0';