" . $port['ifDescr'] . " "); if($array[$device[device_id]][$port[ifIndex]] && $port['ignore'] == "0") { // Check to make sure Port data is cached. $this_port = &$array[$device[device_id]][$port[ifIndex]]; $polled_period = $polled - $port['poll_time']; $update .= "`poll_time` = '".$polled."'"; $update .= ", `poll_prev` = '".$port['poll_time']."'"; $update .= ", `poll_period` = '".$polled_period."'"; /// Copy ifHC[In|Out]Octets values to non-HC if they exist if($this_port['ifHCInOctets'] > 0 && is_numeric($this_port['ifHCInOctets']) && $this_port['ifHCOutOctets'] > 0 && is_numeric($this_port['ifHCOutOctets'])) { echo("HC "); $this_port['ifInOctets'] = $this_port['ifHCInOctets']; $this_port['ifOutOctets'] = $this_port['ifHCOutOctets']; } /// Update IF-MIB data foreach ($data_oids as $oid) { if ( $port[$oid] != $this_port[$oid] && !isset($this_port[$oid])) { $update .= ", `$oid` = NULL"; log_event($oid . ": ".$port[$oid]." -> NULL", $device['device_id'], 'interface', $port['interface_id']); if($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); } } elseif ( $port[$oid] != $this_port[$oid] ) { $update .= ", `$oid` = '".mres($this_port[$oid])."'"; log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device['device_id'], 'interface', $port['interface_id']); if($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); } } } /// Parse description (usually ifAlias) if config option set if(isset($config['port_descr_parser'])) { $port_attribs = array('type','descr','circuit','speed','notes'); include($config['port_descr_parser']); foreach ($port_attribs as $attrib) { $attrib_key = "port_descr_".$attrib; if($port_ifAlias[$attrib]) { if($port_ifAlias[$attrib] != $port[$attrib_key]) { $update .= ", `".$attrib_key."` = '".$port_ifAlias[$attrib]."'"; log_event($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device['device_id'], 'interface', $port['interface_id']); } } } } /// Ende parse ifAlias /// Update IF-MIB metrics foreach ($stat_oids_db as $oid) { $update .= ", `$oid` = '".$this_port[$oid]."'"; $update .= ", `".$oid."_prev` = '".$port[$oid]."'"; $oid_prev = $oid . "_prev"; if($port[$oid]) { $oid_diff = $this_port[$oid] - $port[$oid]; $oid_rate = $oid_diff / $polled_period; if($oid_rate < 0) { $oid_rate = "0"; } $update .= ", `".$oid."_rate` = '".$oid_rate."'"; $update .= ", `".$oid."_delta` = '".$oid_diff."'"; if($debug) {echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n");} } } /// Update RRDs $rrdfile = $host_rrd . "/" . safename($port['ifIndex'] . ".rrd"); if(!is_file($rrdfile)) { $woo = shell_exec($config['rrdtool'] . " create $rrdfile -s 300 \ DS:INOCTETS:DERIVE:600:0:12500000000 \ DS:OUTOCTETS:DERIVE:600:0:12500000000 \ DS:INERRORS:DERIVE:600:0:12500000000 \ DS:OUTERRORS:DERIVE:600:0:12500000000 \ DS:INUCASTPKTS:DERIVE:600:0:12500000000 \ DS:OUTUCASTPKTS:DERIVE:600:0:12500000000 \ DS:INNUCASTPKTS:DERIVE:600:0:12500000000 \ DS:OUTNUCASTPKTS:DERIVE:600:0:12500000000 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797"); } $ifx_rrd = $host_rrd . "/ifx-" . safename($port['ifIndex'] . ".rrd"); $ifx_rrd_cmd = $config['rrdtool'] . " create $ifx_rrd -s 300 \ DS:InBroadcastPkts:DERIVE:600:0:12500000000 \ DS:OutBroadcastPkts:DERIVE:600:0:12500000000 \ DS:InMulticastPkts:DERIVE:600:0:12500000000 \ DS:OutMulticastPkts:DERIVE:600:0:12500000000 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797"; foreach ($stat_oids as $oid) { /// Copy values from array to global variables and force numeric. $$oid = $this_port[$oid]; if(!is_numeric($$oid)) { $$oid = "0"; } } $if_rrd_update = "$polled:$ifInOctets:$ifOutOctets:$ifInErrors:$ifOutErrors:$ifInUcastPkts:$ifOutUcastPkts:$ifInNUcastPkts:$ifOutNUcastPkts"; $ret = rrdtool_update("$rrdfile", $if_rrd_update); if($config['enable_port_Xbcmc'] && $config['os'][$device['os']]['ifXmcbc']) { if(!is_file($ifx_rrd)) { shell_exec($ifx_rrd_cmd); } $ifx_rrd_update = "$polled:$ifHCInBroadcastPkts:$ifHCOutBroadcastPkts:$ifHCInMulticastPkts:$ifHCOutMulticastPkts"; $ret = rrdtool_update($ifx_rrd, $ifx_rrd_update); } /// End Update IF-MIB /// Update PAgP if($this_port['pagpOperationMode']) { foreach ($pagp_oids as $oid) { // Loop the OIDs if ( $this_port[$oid] != $port[$oid] ) { // If data has changed, build a query $update .= ", `$oid` = '".mres($this_port[$oid])."'"; echo("PAgP "); log_event("$oid -> ".$this_port[$oid], $device['device_id'], 'interface', $port['interface_id']); } } } // End Update PAgP /// Do EtherLike-MIB if($config['enable_ports_etherlike']) { include("port-etherlike.inc.php"); } // Update MySQL if ($update) { $update_query = "UPDATE `ports` SET ".$update." WHERE `interface_id` = '" . $port['interface_id'] . "'"; @mysql_query($update_query); $mysql++; if($debug) {echo("\nMYSQL : [ $update_query ]");} } // End Update MySQL unset($update_query); unset($update); // Send alerts for interface flaps. if ($config['warn']['ifdown'] && ($port['ifOperStatus'] != $this_port['ifOperStatus'])) { if ($this_port['ifAlias']) { $falias = preg_replace('/^"/', '', $this_port['ifAlias']); $falias = preg_replace('/"$/', '', $falias); $full = $this_port['ifDescr'] . " (" . $falias . ")"; } else { $full = $this_port['ifDescr']; } switch ($this_port['ifOperStatus']) { case "up": notify($device, "Interface UP - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full . "\nTimestamp: " . date($config['timestamp_format'])); break; case "down": notify($device, "Interface DOWN - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full . "\nTimestamp: " . date($config['timestamp_format'])); break; } } } elseif($port['ignore'] == "0") { echo("Port Deleted?"); // Port missing from SNMP cache? } else { echo("Port Ignored."); } echo("\n"); } ?>