$status = '0';
    }
    if ($status == '1') {
        echo "Up\n";
    } else {
        echo "Down\n";
    }
    if ($status != $device['status']) {
        if ($device['sysContact']) {
            $email = $device['sysContact'];
        } else {
            $email = $config['email_default'];
        }
        mysql_query("UPDATE `devices` SET `status`= '{$status}' WHERE `device_id` = '" . $device['device_id'] . "'");
        if ($status == '1') {
            $stat = "Up";
            mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')");
            //mail($email, "DeviceUp: " . $device['hostname'], "Device Up: " . $device['hostname'] . " at " . date($config['timestamp_format']), $config['email_headers']);
            shell_exec("/usr/bin/smssender +48608653556 \"Device Up: " . $device['hostname'] . " at " . date($config['timestamp_format']) . "\"");
            shell_exec("/usr/bin/smssender +48514572303 \"Device Up: " . $device['hostname'] . " at " . date($config['timestamp_format']) . "\"");
        } else {
            $stat = "Down";
            mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')");
            //mail($email, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date($config['timestamp_format']), $config['email_headers']);
            shell_exec("/usr/bin/smssender +48608653556 \"Device Down: " . $device['hostname'] . " at " . date($config['timestamp_format']) . "\"");
            shell_exec("/usr/bin/smssender +48514572303 \"Device Down: " . $device['hostname'] . " at " . date($config['timestamp_format']) . "\"");
        }
        eventlog("Device status changed to {$stat}", $device['device_id']);
        echo "Status Changed!\n";
    }
}
Exemple #2
0
         if ($device['sysContact']) {
             $email = $device['sysContact'];
         } else {
             $email = $config['email_default'];
         }
         if ($peer['bgpPeerState'] == $bgpPeerState) {
             mail($email, "BGP Session flapped: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session flapped " . formatUptime($bgpPeerFsmEstablishedTime) . " ago.\n\nHostname : " . $device['hostname'] . "\nPeer IP  : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' (' . $peer['astext'] . ')', $config['email_headers']);
             eventlog('BGP Session Flap: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id']);
         } else {
             if ($bgpPeerState == "established") {
                 mail($email, "BGP Session up: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session up since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP  : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' (' . $peer['astext'] . ')', $config['email_headers']);
                 eventlog('BGP Session Up: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id']);
             } else {
                 if ($peer['bgpPeerState'] == "established") {
                     mail($email, "BGP Session down: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session down since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP  : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' (' . $peer['astext'] . ')', $config['email_headers']);
                     eventlog('BGP Session Down: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id']);
                 }
             }
         }
     }
 }
 $peerrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("bgp-" . $peer['bgpPeerIdentifier'] . ".rrd");
 if (!is_file($peerrrd)) {
     $create_rrd = "DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 \\\n      DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 \\\n      DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 \\\n      DS:bgpPeerInTotal:COUNTER:600:U:100000000000 \\\n      DS:bgpPeerEstablished:GAUGE:600:0:U \\\n      RRA:AVERAGE:0.5:1:600 \\\n      RRA:AVERAGE:0.5:6:700 \\\n      RRA:AVERAGE:0.5:24:775 \\\n      RRA:AVERAGE:0.5:288:797 \\\n      RRA:MAX:0.5:1:600 \\\n      RRA:MAX:0.5:6:700 \\\n      RRA:MAX:0.5:24:775 \\\n      RRA:MAX:0.5:288:797";
     rrdtool_create($peerrrd, $create_rrd);
 }
 rrdtool_update("{$peerrrd}", "N:{$bgpPeerOutUpdates}:{$bgpPeerInUpdates}:{$bgpPeerOutTotalMessages}:{$bgpPeerInTotalMesages}:{$bgpPeerFsmEstablishedTime}");
 $update = "UPDATE bgpPeers SET bgpPeerState = '{$bgpPeerState}', bgpPeerAdminStatus = '{$bgpPeerAdminStatus}', ";
 $update .= "bgpPeerFsmEstablishedTime = '{$bgpPeerFsmEstablishedTime}', bgpPeerInUpdates = '{$bgpPeerInUpdates}' , bgpLocalAddr = '{$bgpLocalAddr}' , bgpPeerOutUpdates = '{$bgpPeerOutUpdates}'";
 $update .= " WHERE `device_id` = '" . $device['device_id'] . "' AND bgpPeerIdentifier = '" . $peer['bgpPeerIdentifier'] . "'";
 mysql_query($update);
function renamehost($id, $new)
{
    global $config;
    $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '{$id}'"), 0);
    shell_exec("mv " . $config['rrd_dir'] . "/{$host} " . $config['rrd_dir'] . "/{$new}");
    mysql_query("UPDATE devices SET hostname = '{$new}' WHERE device_id = '{$id}'");
    eventlog("Hostname changed -> {$new} (console)", $id);
}
     eventlog("ifAlias -> {$ifAlias}", $interface['device_id'], $interface['port_id']);
 }
 if ($interface['ifOperStatus'] != $ifOperStatus && $ifOperStatus != "") {
     $update .= $seperator . "`ifOperStatus` = '{$ifOperStatus}'";
     $seperator = ", ";
     eventlog("Interface went {$ifOperStatus}", $interface['device_id'], $interface['port_id']);
 }
 if ($interface['ifAdminStatus'] != $ifAdminStatus && $ifAdminStatus != "") {
     $update .= $seperator . "`ifAdminStatus` = '{$ifAdminStatus}'";
     $seperator = ", ";
     if ($ifAdminStatus == "up") {
         $admin = "enabled";
     } else {
         $admin = "disabled";
     }
     eventlog("Interface {$admin}", $interface['device_id'], $interface['port_id']);
 }
 if ($update) {
     $update_query = "UPDATE `ports` SET ";
     $update_query .= $update;
     $update_query .= " WHERE `port_id` = '" . $interface['port_id'] . "'";
     #echo("Updating : " . $device['hostname'] . " $ifDescr\nSQL :$update_query\n\n");
     $update_result = mysql_query($update_query);
 } else {
     #     echo("Not Updating : " . $device['hostname'] ." $ifDescr ( " . $interface['ifDescr'] . " )\n\n");
 }
 if ($ifOperStatus == "up") {
     $snmp_data_cmd = $config['snmpget'] . " -M " . $config['mibdir'] . " -m IF-MIB -O qv -" . $device['snmp_version'] . " -c " . $device['snmp_community'] . " " . $device['hostname'] . ":" . $device['snmp_port'];
     $snmp_data_cmd .= " ifHCInOctets." . $interface['ifIndex'] . " ifHCOutOctets." . $interface['ifIndex'] . " ifInErrors." . $interface['ifIndex'];
     $snmp_data_cmd .= " ifOutErrors." . $interface['ifIndex'] . " ifInUcastPkts." . $interface['ifIndex'] . " ifOutUcastPkts." . $interface['ifIndex'];
     $snmp_data_cmd .= " ifInNUcastPkts." . $interface['ifIndex'] . " ifOutNUcastPkts." . $interface['ifIndex'];
Exemple #5
0
$query = "SELECT * FROM fanspeed WHERE device_id = '" . $device['device_id'] . "'";
$fan_data = mysql_query($query);
while ($fanspeed = mysql_fetch_array($fan_data)) {
    echo "Checking fan " . $fanspeed['fan_descr'] . "... ";
    $fan_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . ":" . $device['port'] . " " . $fanspeed['fan_oid'] . "|grep -v \"No Such Instance\"";
    $fan = trim(str_replace("\"", "", shell_exec($fan_cmd)));
    if ($fanspeed['fan_precision']) {
        $fan = $fan / $fanspeed['fan_precision'];
    }
    #FIXME also divide the limit here
    $fanrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fan-" . $fanspeed['fan_descr'] . ".rrd");
    if (!is_file($fanrrd)) {
        `rrdtool create {$fanrrd} \\\n     --step 300 \\\n     DS:fan:GAUGE:600:0:20000 \\\n     RRA:AVERAGE:0.5:1:1200 \\\n     RRA:MIN:0.5:12:2400 \\\n     RRA:MAX:0.5:12:2400 \\\n     RRA:AVERAGE:0.5:12:2400`;
    }
    echo $fan . " rpm\n";
    rrdtool_update($fanrrd, "N:{$fan}");
    if ($fanspeed['fan_current'] > $fanspeed['fan_limit'] && $fan <= $fanspeed['fan_limit']) {
        if ($device['sysContact']) {
            $email = $device['sysContact'];
        } else {
            $email = $config['email_default'];
        }
        $msg = "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['fan_descr'] . " is " . $fan . "rpm (Limit " . $fanspeed['fan_limit'];
        $msg .= "rpm) at " . date($config['timestamp_format']);
        mail($email, "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['fan_descr'], $msg, $config['email_headers']);
        echo "Alerting for " . $device['hostname'] . " " . $fanspeed['fan_descr'] . "\n";
        eventlog('Fan speed ' . $fanspeed['fan_descr'] . " under threshold: " . $fanspeed['fan_current'] . " rpm (&gt; " . $fanspeed['fan_limit'] . " rpm)", $device['device_id']);
    }
    mysql_query("UPDATE fanspeed SET fan_current = '{$fan}' WHERE fan_id = '" . $fanspeed['fan_id'] . "'");
}
Exemple #6
0
     if (!is_numeric(${$oid})) {
         ${$oid} = "0";
     }
 }
 $woo = "{$polled}:{$ifInOctets}:{$ifOutOctets}:{$ifInErrors}:{$ifOutErrors}:{$ifInUcastPkts}:{$ifOutUcastPkts}:{$ifInNUcastPkts}:{$ifOutNUcastPkts}";
 $ret = rrdtool_update("{$rrdfile}", $woo);
 /// 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 ";
             eventlog("{$oid} -> " . $this_port[$oid], $device['device_id'], $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} ]";
        $temp = trim(str_replace("\"", "", shell_exec($temp_cmd)));
        if ($temp != 9999) {
            break;
        }
        # TME sometimes sends 999.9 when it is right in the middle of an update;
        sleep(1);
        # Give the TME some time to reset
    }
    if ($temperature['temp_precision']) {
        $temp = $temp / $temperature['temp_precision'];
    }
    $temprrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temp-" . $temperature['temp_descr'] . ".rrd");
    if (!is_file($temprrd)) {
        `rrdtool create {$temprrd} \\\n     --step 300 \\\n     DS:temp:GAUGE:600:-273:1000 \\\n     RRA:AVERAGE:0.5:1:1200 \\\n     RRA:MIN:0.5:12:2400 \\\n     RRA:MAX:0.5:12:2400 \\\n     RRA:AVERAGE:0.5:12:2400`;
    }
    echo $temp . "C\n";
    rrdtool_update($temprrd, "N:{$temp}");
    if ($temperature['temp_current'] < $temperature['temp_limit'] && $temp >= $temperature['temp_limit']) {
        if ($device['sysContact']) {
            $email = $device['sysContact'];
        } else {
            $email = $config['email_default'];
        }
        $msg = "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'] . " is " . $temp . " (Limit " . $temperature['temp_limit'];
        $msg .= ") at " . date($config['timestamp_format']);
        mail($email, "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'], $msg, $config['email_headers']);
        echo "Alerting for " . $device['hostname'] . " " . $temperature['temp_descr'] . "\n";
        eventlog('Temperature ' . $temperature['temp_descr'] . " over threshold: " . $temperature['temp_current'] . " °C (> " . $temperature['temp_limit'] . " °C)", $device['device_id']);
    }
    mysql_query("UPDATE temperature SET temp_current = '{$temp}' WHERE temp_id = '" . $temperature['temp_id'] . "'");
}
Exemple #8
0
<?php

$os = getHostOS($device);
if ($os != $device['os']) {
    $sql = mysql_query("UPDATE `devices` SET `os` = '{$os}' WHERE `device_id` = '" . $device['device_id'] . "'");
    echo "Changed OS! : {$os}\n";
    eventlog("Device OS changed " . $device['os'] . " => {$os}", $device['device_id']);
    $device['os'] = $os;
}
Exemple #9
0
        `rrdtool create {$voltrrd} \\\n     --step 300 \\\n     DS:volt:GAUGE:600:-273:1000 \\\n     RRA:AVERAGE:0.5:1:1200 \\\n     RRA:MIN:0.5:12:2400 \\\n     RRA:MAX:0.5:12:2400 \\\n     RRA:AVERAGE:0.5:12:2400`;
    }
    echo $volt . " V\n";
    rrdtool_update($voltrrd, "N:{$volt}");
    if ($voltage['volt_current'] > $voltage['volt_limit_low'] && $volt <= $voltage['volt_limit_low']) {
        if ($device['sysContact']) {
            $email = $device['sysContact'];
        } else {
            $email = $config['email_default'];
        }
        $msg = "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'] . " is " . $volt . "V (Limit " . $voltage['volt_limit'];
        $msg .= "V) at " . date($config['timestamp_format']);
        mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']);
        echo "Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n";
        eventlog('Voltage ' . $voltage['volt_descr'] . " under threshold: " . $voltage['volt_current'] . " V (&gt; " . $voltage['volt_limit'] . " V)", $device['device_id']);
    } else {
        if ($voltage['volt_current'] < $voltage['volt_limit'] && $volt >= $voltage['volt_limit']) {
            if ($device['sysContact']) {
                $email = $device['sysContact'];
            } else {
                $email = $config['email_default'];
            }
            $msg = "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'] . " is " . $volt . "V (Limit " . $voltage['volt_limit'];
            $msg .= "V) at " . date($config['timestamp_format']);
            mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']);
            echo "Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n";
            eventlog('Voltage ' . $voltage['volt_descr'] . " above threshold: " . $voltage['volt_current'] . " V (&gt; " . $voltage['volt_limit'] . " V)", $device['device_id']);
        }
    }
    mysql_query("UPDATE voltage SET volt_current = '{$volt}' WHERE volt_id = '" . $voltage['volt_id'] . "'");
}