function graph_error($string) { global $vars, $config, $debug, $graphfile; $vars['bg'] = 'FFBBBB'; include 'includes/graphs/common.inc.php'; $rrd_options .= ' HRULE:0#555555'; $rrd_options .= " --title='" . $string . "'"; rrdtool_graph($graphfile, $rrd_options); if ($height > '99') { shell_exec($rrd_cmd); d_echo('<pre>' . $rrd_cmd . '</pre>'); if (is_file($graphfile) && !$debug) { header('Content-type: image/png'); $fd = fopen($graphfile, 'r'); fpassthru($fd); fclose($fd); unlink($graphfile); exit; } } else { if (!$debug) { header('Content-type: image/png'); } $im = imagecreate($width, $height); $px = (imagesx($im) - 7.5 * strlen($string)) / 2; imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0)); imagepng($im); imagedestroy($im); exit; } }
function influx_update($device, $measurement, $tags = array(), $fields) { global $influxdb, $config, $console_color; if ($influxdb !== false) { $tmp_fields = array(); $tmp_tags['hostname'] = $device['hostname']; foreach ($tags as $k => $v) { $v = preg_replace(array('/ /', '/,/', '/=/'), array('\\ ', '\\,', '\\='), $v); if (empty($v)) { $v = '_blank_'; } $tmp_tags[$k] = $v; } foreach ($fields as $k => $v) { $tmp_fields[$k] = force_influx_data('f', $v); } d_echo("\nInfluxDB data:\n"); d_echo($measurement); d_echo($tmp_tags); d_echo($tmp_fields); d_echo("\nEND\n"); if ($config['noinfluxdb'] !== true) { $points = array(new InfluxDB\Point($measurement, null, $tmp_tags, $tmp_fields)); $result = $influxdb->writePoints($points); } else { print $console_color->convert('[%gInfluxDB Disabled%n] ', false); } //end if } //end if }
/** * Create and run a new process * Most arguments match proc_open() * * @param string $cmd the command to execute * @param array $descriptorspec the definition of pipes to initialize * @param null $cwd working directory to change to * @param array|null $env array of environment variables to set * @param bool $blocking set the output pipes to blocking (default: false) * @throws Exception the command was unable to execute */ public function __construct($cmd, $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")), $cwd = null, $env = null, $blocking = false) { d_echo("Starting process: {$cmd}"); $this->_process = proc_open($cmd, $descriptorspec, $this->_pipes, $cwd, $env); if (!is_resource($this->_process)) { throw new Exception("Command failed: {$cmd}"); } stream_set_blocking($this->_pipes[1], $blocking); stream_set_blocking($this->_pipes[2], $blocking); $this->_synchronous = true; }
/** * Closes the pipe to RRDTool * * @return integer * @param resource rrd_process * @param array rrd_pipes */ function rrdtool_pipe_close($rrd_process, &$rrd_pipes) { d_echo(stream_get_contents($rrd_pipes[1])); d_echo(stream_get_contents($rrd_pipes[2])); fclose($rrd_pipes[0]); fclose($rrd_pipes[1]); fclose($rrd_pipes[2]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $return_value = proc_close($rrd_process); return $return_value; }
function influx_update($device, $measurement, $tags, $fields) { global $influxdb, $config; if ($influxdb !== false) { $tmp_fields = array(); $tmp_tags['hostname'] = $device['hostname']; foreach ($tags as $k => $v) { $v = preg_replace(array('/ /', '/,/', '/=/'), array('\\ ', '\\,', '\\='), $v); if (empty($v)) { $v = '_blank_'; } $tmp_tags[$k] = $v; } foreach ($fields as $k => $v) { $tmp_fields[$k] = force_influx_data($v); if ($tmp_fields[$k] === null) { unset($tmp_fields[$k]); } } d_echo("\nInfluxDB data:\n"); d_echo($measurement); d_echo($tmp_tags); d_echo($tmp_fields); d_echo("\nEND\n"); if ($config['noinfluxdb'] !== true) { $points = array(new InfluxDB\Point($measurement, null, $tmp_tags, $tmp_fields)); try { $result = $influxdb->writePoints($points); } catch (Exception $e) { d_echo("Caught exception: " . $e->getMessage() . PHP_EOL); d_echo($e->getTrace()); } } else { c_echo("[%gInfluxDB Disabled%n]\n"); } //end if } //end if }
d_echo("{$cbgp_data}\n"); } else { // FIXME - move to function $cbgp_cmd = $config['snmpget'] . ' -M ' . $config['mibdir'] . ' -m CISCO-BGP4-MIB -Ovq ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port']; $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerPrefixThreshold.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; d_echo("{$cbgp_cmd}\n"); $cbgp_data = preg_replace('/^OID.*$/', '', trim(`{$cbgp_cmd}`)); $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); d_echo("{$cbgp_data}\n"); } //end if list($cbgpPeerAcceptedPrefixes, $cbgpPeerDeniedPrefixes, $cbgpPeerPrefixAdminLimit, $cbgpPeerPrefixThreshold, $cbgpPeerPrefixClearThreshold, $cbgpPeerAdvertisedPrefixes, $cbgpPeerSuppressedPrefixes, $cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); } //end if if ($device['os'] == 'junos') { // Missing: cbgpPeerAdminLimit cbgpPeerPrefixThreshold cbgpPeerPrefixClearThreshold cbgpPeerSuppressedPrefixes cbgpPeerWithdrawnPrefixes $safis['unicast'] = 1; $safis['multicast'] = 2; if (!isset($peerIndexes)) { $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'] . '/mibs/junos'); foreach ($j_bgp as $index => $entry) { switch ($entry['jnxBgpM2PeerRemoteAddrType']) { case 'ipv4': $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr']));
<?php if (!empty($agent_data['app']['nginx'])) { $nginx = $agent_data['app']['nginx']; } else { // Polls nginx statistics from script via SNMP $nginx = snmp_get($device, 'nsExtendOutputFull.5.110.103.105.110.120', '-Ovq', 'NET-SNMP-EXTEND-MIB'); } $nginx_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/app-nginx-' . $app['app_id'] . '.rrd'; echo ' nginx'; list($active, $reading, $writing, $waiting, $req) = explode("\n", $nginx); if (!is_file($nginx_rrd)) { rrdtool_create($nginx_rrd, '--step 300 DS:Requests:DERIVE:600:0:125000000000 DS:Active:GAUGE:600:0:125000000000 DS:Reading:GAUGE:600:0:125000000000 DS:Writing:GAUGE:600:0:125000000000 DS:Waiting:GAUGE:600:0:125000000000 ' . $config['rrd_rra']); } d_echo("active: {$active} reading: {$reading} writing: {$writing} waiting: {$waiting} Requests: {$req}"); $fields = array('Requests' => $req, 'Active' => $active, 'Reading' => $reading, 'Writing' => $writing, 'Waiting' => $waiting); rrdtool_update($nginx_rrd, $fields); $tags = array('name' => 'nginx', 'app_id' => $app['app_id']); influx_update($device, 'app', $tags, $fields); // Unset the variables we set here unset($nginx); unset($nginx_rrd); unset($active); unset($reading); unset($writing); unset($req);
$txpow = $value['bsnAPIfPhyTxPowerLevel']; $type = $value['bsnAPIfType']; $interference = 128 + $interferences[$key . '.' . $channel]['bsnAPIfInterferencePower']; $radioutil = $loadParams[$key]['bsnAPIfLoadChannelUtilization']; // TODO $numactbssid = 0; $nummonbssid = 0; $nummonclients = 0; d_echo(" name: {$name}\n"); d_echo(" radionum: {$radionum}\n"); d_echo(" type: {$type}\n"); d_echo(" channel: {$channel}\n"); d_echo(" txpow: {$txpow}\n"); d_echo(" radioutil: {$radioutil}\n"); d_echo(" numasoclients: {$numasoclients}\n"); d_echo(" interference: {$interference}\n"); // if there is a numeric channel, assume the rest of the data is valid, I guess if (!is_numeric($channel)) { continue; } $rrd_name = array('arubaap', $name . $radionum); $rrd_def = array('DS:channel:GAUGE:600:0:200', 'DS:txpow:GAUGE:600:0:200', 'DS:radioutil:GAUGE:600:0:100', 'DS:nummonclients:GAUGE:600:0:500', 'DS:nummonbssid:GAUGE:600:0:200', 'DS:numasoclients:GAUGE:600:0:500', 'DS:interference:GAUGE:600:0:2000'); $fields = array('channel' => $channel, 'txpow' => $txpow, 'radioutil' => $radioutil, 'nummonclients' => $nummonclients, 'nummonbssid' => $nummonbssid, 'numasoclients' => $numasoclients, 'interference' => $interference); $tags = compact('name', 'radionum', 'rrd_name', 'rrd_def'); data_update($device, 'arubaap', $tags, $fields); $foundid = 0; for ($z = 0; $z < sizeof($ap_db); $z++) { if ($ap_db[$z]['name'] == $name && $ap_db[$z]['radio_number'] == $radionum) { $foundid = $ap_db[$z]['accesspoint_id']; $ap_db[$z]['seen'] = 1; continue;
// It seems that PBN guys don't care about ieee 802.1d :-( // So try to find the right port with some crazy conversations $dp_value = dechex($stp_port['priority']); $dp_value = $dp_value . '00'; $dp_value = hexdec($dp_value); if ($stp_raw[$port]['dot1dStpPortDesignatedPort']) { $dp = $stp_raw[$port]['dot1dStpPortDesignatedPort'] - $dp_value; $stp_port['designatedPort'] = $dp; } } else { // Port saved in format priority+port (ieee 802.1d-1998: clause 8.5.5.1) $dp = substr($stp_raw[$port]['dot1dStpPortDesignatedPort'], -2); //discard the first octet (priority part) $stp_port['designatedPort'] = hexdec($dp); } d_echo($stp_port); // Write to db if (!dbFetchCell('SELECT 1 FROM `ports_stp` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $stp_port['port_id']))) { dbInsert($stp_port, 'ports_stp'); echo '+'; } } } // Delete STP ports from db if absent in SNMP query $stp_port_db = dbFetchRows('SELECT * FROM `ports_stp` WHERE `device_id` = ?', array($device['device_id'])); //d_echo($stp_port_db); foreach ($stp_port_db as $port => $value) { $if_index = dbFetchCell('SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $value['port_id'])); if ($if_index != $stp_raw[$if_index]['dot1dStpPort']) { dbDelete('ports_stp', '`device_id` = ? AND `port_id` = ?', array($device['device_id'], $value['port_id'])); echo '-';
function is_mib_poller_enabled($device) { if (!is_module_enabled('poller', 'mib')) { return false; } if (!is_dev_attrib_enabled($device, 'poll_mib')) { d_echo('MIB module disabled for ' . $device['hostname'] . "\n"); return false; } return true; }
// Let's log some debugging d_echo("\n\nAdjacency Component: " . $key . "\n"); d_echo(" Label: " . $array['label'] . "\n"); d_echo(" Index: " . $array['index'] . "\n"); d_echo(" Status: " . $array['status'] . "\n"); d_echo(" Message: " . $array['error'] . "\n"); } elseif ($array['otvtype'] == 'endpoint') { $count = 0; $endpoint = $array['endpoint']; if (isset($count_mac[$endpoint])) { $count = $count_mac[$endpoint]; } // Let's log some debugging d_echo("\n\nEndpoint Component: " . $key . "\n"); d_echo(" Label: " . $array['label'] . "\n"); d_echo(" MAC Count: " . $count . "\n"); $rrd_name = array('cisco', 'otv', $endpoint, 'mac'); $rrd_def = 'DS:count:GAUGE:600:0:U'; $fields = array('count' => $count); $tags = compact('endpoint', 'rrd_name', 'rrd_def'); data_update($device, 'cisco-otv-mac', $tags, $fields); } // End If } // End foreach components // Write the Components back to the DB. $component->setComponentPrefs($device['device_id'], $components); } // end if count components // Clean-up after yourself! unset($components, $component, $module);
$rrd_name = array('sla', $sla_nr); $rrd_def = 'DS:rtt:GAUGE:600:0:300000'; $tags = compact('sla_nr', 'rrd_name', 'rrd_def'); data_update($device, 'sla', $tags, $fields); // Let's gather some per-type fields. switch ($rtt_type) { case 'jitter': $jitter = array('PacketLossSD' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.26'][$sla_nr], 'PacketLossDS' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.27'][$sla_nr], 'PacketOutOfSequence' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.28'][$sla_nr], 'PacketMIA' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.29'][$sla_nr], 'PacketLateArrival' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.30'][$sla_nr], 'MOS' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.42'][$sla_nr] / 100, 'ICPIF' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.43'][$sla_nr], 'OWAvgSD' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.49'][$sla_nr], 'OWAvgDS' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.50'][$sla_nr], 'AvgSDJ' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.47'][$sla_nr], 'AvgDSJ' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.48'][$sla_nr]); $rrd_name = array('sla', $sla_nr, $rtt_type); $rrd_def = array('DS:PacketLossSD:GAUGE:600:0:U', 'DS:PacketLossDS:GAUGE:600:0:U', 'DS:PacketOutOfSequence:GAUGE:600:0:U', 'DS:PacketMIA:GAUGE:600:0:U', 'DS:PacketLateArrival:GAUGE:600:0:U', 'DS:MOS:GAUGE:600:0:U', 'DS:ICPIF:GAUGE:600:0:U', 'DS:OWAvgSD:GAUGE:600:0:U', 'DS:OWAvgDS:GAUGE:600:0:U', 'DS:AvgSDJ:GAUGE:600:0:U', 'DS:AvgDSJ:GAUGE:600:0:U'); $tags = compact('rrd_name', 'rrd_def', 'sla_nr', 'rtt_type'); data_update($device, 'sla', $tags, $jitter); $fields = array_merge($fields, $jitter); break; case 'icmpjitter': $icmpjitter = array('PacketLoss' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.26'][$sla_nr], 'PacketOosSD' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.28'][$sla_nr], 'PacketOosDS' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.29'][$sla_nr], 'PacketLateArrival' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.32'][$sla_nr], 'JitterAvgSD' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.45'][$sla_nr], 'JitterAvgDS' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.46'][$sla_nr], 'LatencyOWAvgSD' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.47'][$sla_nr], 'LatencyOWAvgDS' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.48'][$sla_nr], 'JitterIAJOut' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.49'][$sla_nr], 'JitterIAJIn' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.4.1.50'][$sla_nr]); $rrd_name = array('sla', $sla_nr, $rtt_type); $rrd_def = array('DS:PacketLoss:GAUGE:600:0:U', 'DS:PacketOosSD:GAUGE:600:0:U', 'DS:PacketOosDS:GAUGE:600:0:U', 'DS:PacketLateArrival:GAUGE:600:0:U', 'DS:JitterAvgSD:GAUGE:600:0:U', 'DS:JitterAvgDS:GAUGE:600:0:U', 'DS:LatencyOWAvgSD:GAUGE:600:0:U', 'DS:LatencyOWAvgDS:GAUGE:600:0:U', 'DS:JitterIAJOut:GAUGE:600:0:U', 'DS:JitterIAJIn:GAUGE:600:0:U'); $tags = compact('rrd_name', 'rrd_def', 'sla_nr', 'rtt_type'); data_update($device, 'sla', $tags, $icmpjitter); $fields = array_merge($fields, $icmpjitter); break; } d_echo("The following datasources were collected for #" . $sla['sla_nr'] . ":\n"); d_echo($fields); // Update the DB if necessary if (count($update) > 0) { $updated = dbUpdate($update, 'slas', '`sla_id` = ?', array($sla['sla_id'])); } } }
if ($device['os'] == 'ipoman') { echo ' IPOMANII-MIB '; // Inlet Disabled due to the fact thats it's Kwh instead of just Watt if (!is_array($cache['ipoman'])) { d_echo('outletConfigDesc '); $cache['ipoman']['out'] = snmpwalk_cache_multi_oid($device, 'outletConfigDesc', $cache['ipoman']['out'], 'IPOMANII-MIB'); d_echo('outletConfigLocation '); $cache['ipoman']['out'] = snmpwalk_cache_multi_oid($device, 'outletConfigLocation', $cache['ipoman']['out'], 'IPOMANII-MIB'); // echo("inletConfigDesc "); // $cache['ipoman']['in'] = snmpwalk_cache_multi_oid($device, "inletConfigDesc", $cache['ipoman'], "IPOMANII-MIB"); } // $oids_in = array(); $oids_out = array(); // echo("inletStatusWH "); // $oids_in = snmpwalk_cache_multi_oid($device, "inletStatusWH", $oids_in, "IPOMANII-MIB"); d_echo('outletStatusWH '); $oids_out = snmpwalk_cache_multi_oid($device, 'outletStatusWH', $oids_out, 'IPOMANII-MIB'); // if (is_array($oids_in)) // { // foreach ($oids_in as $index => $entry) // { // $cur_oid = '.1.3.6.1.4.1.2468.1.4.2.1.3.1.3.1.5.' . $index; // $divisor = 10; // $descr = (trim($cache['ipoman']['in'][$index]['inletConfigDesc'],'"') != '' ? trim($cache['ipoman']['in'][$index]['inletConfigDesc'],'"') : "Inlet $index"); // $power = $entry['inletStatusWH'] / $divisor; // // discover_sensor($valid['sensor'], 'power', $device, $cur_oid, '1.3.1.3.'.$index, 'ipoman', $descr, $divisor, '1', NULL, NULL, NULL, NULL, $power); // // FIXME: iPoMan 1201 also says it has 2 inlets, at least until firmware 1.06 - wtf? // } // } if (is_array($oids_out)) {
if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { d_echo("Changed mac address for {$ip} from {$old_mac} to {$clean_mac}\n"); log_event("MAC change: {$ip} : " . mac_clean_to_readable($old_mac) . ' -> ' . mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); } dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip)); echo '.'; } else { if (isset($interface['port_id'])) { echo '+'; // echo("Add MAC $mac\n"); $insert_data = array('port_id' => $interface['port_id'], 'mac_address' => $clean_mac, 'ipv4_address' => $ip); dbInsert($insert_data, 'ipv4_mac'); } } //end if } //end if } //end foreach $sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '" . $device['device_id'] . "'"; foreach (dbFetchRows($sql) as $entry) { $entry_mac = $entry['mac_address']; $entry_if = $entry['port_id']; if (!$mac_table[$entry_if][$entry_mac]) { dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac)); d_echo("Removing MAC {$entry_mac} from interface " . $interface['ifName']); echo '-'; } } echo "\n"; unset($mac);
<?php /* * LibreNMS Ubiquiti EdgeSwitch memory information module * * Copyright (c) 2016 Cercel Valentin <*****@*****.**> * 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 ($device['os'] == "edgeswitch") { d_echo('EdgeSwitch Memory:'); //EdgeSwitch-SWITCHING-MIB::agentSwitchCpuProcessMemFree $avail = snmp_get($device, '.1.3.6.1.4.1.4413.1.1.1.1.4.1.0', '-Oqv'); //EdgeSwitch-SWITCHING-MIB::agentSwitchCpuProcessMemAvailable $total = snmp_get($device, '.1.3.6.1.4.1.4413.1.1.1.1.4.2.0', '-Oqv'); $used = $total - $avail; $percent = $used / $total * 100; if (is_numeric($total) && is_numeric($avail)) { discover_mempool($valid_mempool, $device, 0, 'edgeswitch', 'Memory', '1', null, null); } }
<?php echo 'Storage : '; // Include all discovery modules $include_dir = 'includes/discovery/storage'; require 'includes/include-dir.inc.php'; // Remove storage which weren't redetected here $sql = "SELECT * FROM `storage` WHERE `device_id` = '" . $device['device_id'] . "'"; d_echo($valid_storage); foreach (dbFetchRows($sql) as $test_storage) { $storage_index = $test_storage['storage_index']; $storage_mib = $test_storage['storage_mib']; d_echo($storage_index . ' -> ' . $storage_mib . "\n"); if (!$valid_storage[$storage_mib][$storage_index]) { echo '-'; dbDelete('storage', '`storage_id` = ?', array($test_storage['storage_id'])); } unset($storage_index); unset($storage_mib); } unset($valid_storage); echo "\n";
function location_to_latlng($device) { global $config; if (function_check('curl_version') !== true) { d_echo("Curl support for PHP not enabled\n"); return false; } $bad_loc = false; $device_location = $device['location']; if (!empty($device_location)) { $new_device_location = preg_replace("/ /", "+", $device_location); // We have a location string for the device. $loc = parse_location($device_location); if (!is_array($loc)) { $loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device_location)); } if (is_array($loc) === false) { // Grab data from which ever Geocode service we use. switch ($config['geoloc']['engine']) { case "google": default: d_echo("Google geocode engine being used\n"); $api_key = $config['geoloc']['api_key']; if (!empty($api_key)) { d_echo("Use Google API key: {$api_key}\n"); $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address={$new_device_location}&key={$api_key}"; } else { $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address={$new_device_location}"; } break; } $curl_init = curl_init($api_url); set_curl_proxy($curl_init); curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true); $data = json_decode(curl_exec($curl_init), true); // Parse the data from the specific Geocode services. switch ($config['geoloc']['engine']) { case "google": default: if ($data['status'] == 'OK') { $loc = $data['results'][0]['geometry']['location']; } else { $bad_loc = true; } break; } if ($bad_loc === true) { d_echo("Bad lat / lng received\n"); } else { $loc['timestamp'] = array('NOW()'); $loc['location'] = $device_location; if (dbInsert($loc, 'locations')) { d_echo("Device lat/lng created\n"); } else { d_echo("Device lat/lng could not be created\n"); } } } else { d_echo("Using cached lat/lng from other device\n"); } } }
<?php /* * LibreNMS * * Copyright (c) 2016 Cercel Valentin (crc@nuamchefazi.ro) * 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 ($device['os'] == 'hwg-ste2') { d_echo('HWg STE2 Humidity '); $oid = '.1.3.6.1.4.1.21796.4.9.3.1.4.1'; $sensorType = 'ste2_humidity'; $descr = 'Input 1 Humidity'; $humidity = snmp_get($device, $oid, '-Osqnv'); if ($humidity !== false) { discover_sensor($valid['sensor'], 'humidity', $device, $oid, '1', $sensorType, $descr, '1', '1', null, null, null, null, $humidity); } }
function is_client_authorized($clientip) { global $config; if (isset($config['allow_unauth_graphs']) && $config['allow_unauth_graphs']) { d_echo("Unauthorized graphs allowed\n"); return true; } if (isset($config['allow_unauth_graphs_cidr'])) { foreach ($config['allow_unauth_graphs_cidr'] as $range) { if (Net_IPv4::ipInNetwork($clientip, $range)) { d_echo("Unauthorized graphs allowed from {$range}\n"); return true; } } } return false; }
<?php if ($device['os'] == 'pbn') { echo 'PBN-MEMORY-POOL: '; // find out wich build number we have preg_match('/^.* Build (?<build>\\d+)/', $device['version'], $version); d_echo($version); // specified MIB supported since build 16607 if ($version[build] >= 16607) { $mibdir = $config['mibdir'] . '/pbn' . ':' . $config['mibdir']; $usage = snmp_get($device, 'nmsMemoryPoolUtilization.0', '-OUvQ', 'NMS-MEMORY-POOL-MIB', $mibdir); if (is_numeric($usage)) { discover_mempool($valid_mempool, $device, 0, 'pbn-mem', 'Main Memory', '100', null, null); } } }
$iind = $index; } else { $arrindex = explode(".", $index); $iind = (int) end($arrindex) + 0; } if (is_int($iind)) { $storage_cache10[$iind] = $ventry; } } d_echo($storage_cache10); foreach ($storage_cache2['eql-storage'] as $index => $vsentry) { if (!array_key_exists('eqliscsiVolumeStatusAvailable', $vsentry)) { continue; } if (is_int($index)) { $iind = $index; } else { $arrindex = explode(".", $index); $iind = (int) end($arrindex) + 0; } if (is_int($iind)) { $storage_cache20[$iind] = $vsentry; } } d_echo($storage_cache20); $entry1 = $storage_cache10[$storage[storage_index]]; $entry2 = $storage_cache20[$storage[storage_index]]; $storage['units'] = 1000000; $storage['size'] = $entry1['eqliscsiVolumeSize'] * $storage['units']; $storage['used'] = $entry2['eqliscsiVolumeStatusAllocatedSpace'] * $storage['units']; $storage['free'] = $storage['size'] - $storage['used'];
function poll_mibs($device, &$graphs) { if (!is_mib_poller_enabled($device)) { return; } echo 'MIB: polling '; d_echo("\n"); foreach (load_device_mibs($device) as $name => $module) { echo "{$name} "; d_echo("\n"); $oids = snmpwalk_cache_oid($device, $name, array(), $module, null, "-OQUsb"); d_print_r($oids); save_mibs($device, $name, $oids, load_mibdefs($module, $name), $graphs); } echo "\n"; }
<?php // RFC1628 UPS if (isset($config['modules_compat']['rfc1628'][$device['os']]) && $config['modules_compat']['rfc1628'][$device['os']]) { echo 'RFC1628 '; $oids = trim(snmp_walk($device, '1.3.6.1.2.1.33.1.3.2.0', '-OsqnU')); d_echo($oids . "\n"); list($unused, $numPhase) = explode(' ', $oids); for ($i = 1; $i <= $numPhase; $i++) { $freq_oid = "1.3.6.1.2.1.33.1.3.3.1.2.{$i}"; $descr = 'Input'; if ($numPhase > 1) { $descr .= " Phase {$i}"; } $current = snmp_get($device, $freq_oid, '-Oqv') / 10; $type = 'rfc1628'; $divisor = 10; if ($device['os'] == 'huaweiups') { $divisor = 100; } $index = '3.2.0.' . $i; discover_sensor($valid['sensor'], 'frequency', $device, $freq_oid, $index, $type, $descr, $divisor, '1', null, null, null, null, $current); } $freq_oid = '1.3.6.1.2.1.33.1.4.2.0'; $descr = 'Output'; $current = snmp_get($device, $freq_oid, '-Oqv') / 10; $type = 'rfc1628'; $divisor = 10; if ($device['os'] == 'huaweiups') { $divisor = 100; }
foreach ($cip_oids as $oid) { foreach (array('input', 'output') as $dir) { $oid_dir = $oid . '_' . $dir; $acc['update'][$oid_dir] = $this_ma[$oid][$dir]; $acc['update'][$oid_dir . '_prev'] = $acc[$oid_dir]; $oid_prev = $oid_dir . '_prev'; if ($this_ma[$oid][$dir]) { $oid_diff = $this_ma[$oid][$dir] - $acc[$oid_dir]; $oid_rate = $oid_diff / $polled_period; $acc['update'][$oid_dir . '_rate'] = $oid_rate; $acc['update'][$oid_dir . '_delta'] = $oid_diff; d_echo("\n {$oid_dir} ({$oid_diff} B) {$oid_rate} Bps {$polled_period} secs\n"); } } } d_echo("\n" . $acc['hostname'] . ' ' . $acc['ifDescr'] . " {$mac} -> {$b_in}:{$b_out}:{$p_in}:{$p_out} "); $rrdfile = $config['rrd_dir'] . '/' . $device['hostname'] . '/' . safename('cip-' . $acc['ifIndex'] . '-' . $acc['mac'] . '.rrd'); if (!is_file($rrdfile)) { rrdtool_create($rrdfile, 'DS:IN:COUNTER:600:0:12500000000 DS:OUT:COUNTER:600:0:12500000000 DS:PIN:COUNTER:600:0:12500000000 DS:POUT:COUNTER:600:0:12500000000 ' . $config['rrd_rra']); } // FIXME - use memcached to make sure these values don't go backwards? $fields = array('IN' => $b_in, 'OUT' => $b_out, 'PIN' => $p_in, 'POUT' => $p_out); rrdtool_update($rrdfile, $fields); $tags = array('ifIndex' => $acc['ifIndex'], 'mac' => $acc['mac']); influx_update($device, 'cip', $tags, $fields); if ($acc['update']) { // Do Updates dbUpdate($acc['update'], 'mac_accounting', '`ma_id` = ?', array($acc['ma_id']));
<?php echo 'Signal: '; // Include all discovery modules $include_dir = 'includes/discovery/sensors/signal'; require 'includes/include-dir.inc.php'; d_echo($valid['sensor']['signal']); check_valid_sensors($device, 'signal', $valid['sensor']); echo "\n";
// MIB-Dell-10892::temperatureProbeLowerNonCriticalThreshold.1.1 = INTEGER: 70 // MIB-Dell-10892::temperatureProbeLowerCriticalThreshold.1.1 = INTEGER: 30 // MIB-Dell-10892::temperatureProbeProbeCapabilities.1.1 = INTEGER: 0 if (strstr($device['hardware'], 'Dell')) { // stuff partially copied from akcp sensor $oids = snmp_walk($device, 'temperatureProbeStatus', '-Osqn', 'MIB-Dell-10892'); d_echo($oids . "\n"); $oids = trim($oids); if ($oids) { echo 'Dell OMSA '; } foreach (explode("\n", $oids) as $data) { $data = trim($data); if ($data) { list($oid, $status) = explode(' ', $data, 2); d_echo('status : ' . $status . "\n"); if ($status == 'ok') { // 2 = normal, 0 = not connected $split_oid = explode('.', $oid); $temperature_id = $split_oid[count($split_oid) - 2] . '.' . $split_oid[count($split_oid) - 1]; $descr_oid = ".1.3.6.1.4.1.674.10892.1.700.20.1.8.{$temperature_id}"; $temperature_oid = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.{$temperature_id}"; $limit_oid = ".1.3.6.1.4.1.674.10892.1.700.20.1.10.{$temperature_id}"; $warnlimit_oid = ".1.3.6.1.4.1.674.10892.1.700.20.1.11.{$temperature_id}"; $lowwarnlimit_oid = ".1.3.6.1.4.1.674.10892.1.700.20.1.12.{$temperature_id}"; $lowlimit_oid = ".1.3.6.1.4.1.674.10892.1.700.20.1.13.{$temperature_id}"; $descr = trim(snmp_get($device, $descr_oid, '-Oqv', 'MIB-Dell-10892'), '"'); $temperature = snmp_get($device, $temperature_oid, '-Oqv', 'MIB-Dell-10892'); $lowwarnlimit = snmp_get($device, $lowwarnlimit_oid, '-Oqv', 'MIB-Dell-10892'); $warnlimit = snmp_get($device, $warnlimit_oid, '-Oqv', 'MIB-Dell-10892'); $limit = snmp_get($device, $limit_oid, '-Oqv', 'MIB-Dell-10892');
* the source code distribution for details. */ if ($device['os'] == 'cimc') { // Let's add some power sensors. $pwr_board = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.719.1.9.14'); /* * False == OID not found - this is not an error. * null == timeout or something else that caused an error. */ if (is_null($pwr_board)) { echo "Error\n"; } else { // No Error, lets process things. $index = 1; // Board Input Power $oid = '.1.3.6.1.4.1.9.9.719.1.9.14.1.4'; $description = "MB Input Power"; d_echo($oid . " - " . $description . " - " . $pwr_board[$oid][$index] . "\n"); discover_sensor($valid['sensor'], 'power', $device, $oid . "." . $index, 'mb-input-power', 'cimc', $description, '1', '1', null, null, null, null, $temp_board[$oid][$index]); // Board Input Current $oid = '.1.3.6.1.4.1.9.9.719.1.9.14.1.8'; $description = "MB Input Current"; d_echo($oid . " - " . $description . " - " . $pwr_board[$oid][$index] . "\n"); discover_sensor($valid['sensor'], 'current', $device, $oid . "." . $index, 'mb-input-current', 'cimc', $description, '1', '1', null, null, null, null, $temp_board[$oid][$index]); // Board Input Voltage $oid = '.1.3.6.1.4.1.9.9.719.1.9.14.1.12'; $description = "MB Input Voltage"; d_echo($oid . " - " . $description . " - " . $pwr_board[$oid][$index] . "\n"); discover_sensor($valid['sensor'], 'voltage', $device, $oid . "." . $index, 'mb-input-voltage', 'cimc', $description, '1', '1', null, null, null, null, $temp_board[$oid][$index]); } }
if (!empty($hrSystemUptime) && !strpos($hrSystemUptime, 'No') && $device['os'] != 'windows') { // Move uptime into agent_uptime $agent_uptime = $uptime; $uptime = floor($hrSystemUptime / 100); echo 'Using hrSystemUptime (' . $uptime . "s)\n"; } else { $uptime = floor($poll_device['sysUpTime'] / 100); echo 'Using SNMP Agent Uptime (' . $uptime . "s)\n "; } //end if } //end if if ($device["os"] != "edgeswitch") { if ($snmp_uptime > $uptime && is_numeric($snmp_uptime)) { $uptime = $snmp_uptime; d_echo('hrSystemUptime or sysUpTime looks like to have rolled, using snmpEngineTime instead'); } } if (is_numeric($uptime) && $config['os'][$device['os']]['bad_uptime'] !== true) { if ($uptime < $device['uptime']) { log_event('Device rebooted after ' . formatUptime($device['uptime']), $device, 'reboot', $device['uptime']); } $tags = array('rrd_def' => 'DS:uptime:GAUGE:600:0:U'); data_update($device, 'uptime', $tags, $uptime); $graphs['uptime'] = true; echo 'Uptime: ' . formatUptime($uptime) . "\n"; $update_array['uptime'] = $uptime; } //end if $poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']); // Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
if ($mac != $old_mac && $mac != '') { d_echo("Changed mac address for {$ip} from {$old_mac} to {$mac}\n"); log_event("MAC change: {$ip} : " . mac_clean_to_readable($old_mac) . ' -> ' . mac_clean_to_readable($mac), $device, 'interface', $port_id); dbUpdate(array('mac_address' => $mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND context_name=?', array($port_id, $ip, $context)); } d_echo(null, '.'); } elseif (isset($interface['port_id'])) { d_echo(null, '+'); $insert_data[] = array('port_id' => $port_id, 'mac_address' => $mac, 'ipv4_address' => $ip, 'context_name' => $context); } } } // add new entries if (!empty($insert_data)) { dbBulkInsert($insert_data, 'ipv4_mac'); } // remove stale entries foreach ($existing_data as $entry) { $entry_mac = $entry['mac_address']; $entry_if = $entry['port_id']; $entry_ip = $entry['ipv4_address']; if ($arp_table[$entry_if][$entry_ip] != $entry_mac) { dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address`=? AND `ipv4_address`=? AND `context_name`=?', array($entry_if, $entry_mac, $entry_ip, $context)); d_echo(null, '-'); } } echo PHP_EOL; unset($existing_data, $arp_table, $insert_data, $sql, $params, $context); unset($device['context_name']); } unset($vrfs_lite_cisco);
foreach (dbFetchRows('SELECT DISTINCT(`ospfNbrIpAddr`),`device_id` FROM `ospf_nbrs` WHERE `device_id`=?', array($device['device_id'])) as $nbr) { $ip = $nbr['ospfNbrIpAddr']; if (match_network($config['autodiscovery']['nets-exclude'], $ip)) { echo 'x'; continue; } if (!match_network($config['nets'], $ip)) { echo 'i'; continue; } $name = gethostbyaddr($ip); $remote_device_id = discover_new_device($name, $device, 'OSPF'); } } else { echo "disabled\n"; } d_echo($link_exists); $sql = "SELECT * FROM `links` AS L, `ports` AS I WHERE L.local_port_id = I.port_id AND I.device_id = '" . $device['device_id'] . "'"; foreach (dbFetchRows($sql) as $test) { $local_port_id = $test['local_port_id']; $remote_hostname = $test['remote_hostname']; $remote_port = $test['remote_port']; d_echo("{$local_port_id} -> {$remote_hostname} -> {$remote_port} \n"); if (!$link_exists[$local_port_id][$remote_hostname][$remote_port]) { echo '-'; $rows = dbDelete('links', '`id` = ?', array($test['id'])); d_echo("{$rows} deleted "); } } unset($link_exists); echo "\n";