remove some old files

git-svn-id: http://www.observium.org/svn/observer/trunk@493 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2009-10-28 13:51:15 +00:00
parent 1f1eda9764
commit 750799c64d
8 changed files with 67 additions and 350 deletions

View File

@@ -1,41 +0,0 @@
#!/usr/bin/perl
# depends on availability of status and extended status info from your
# Apache webserver -- your httpd.conf needs to include something like the
# following: (uncommented)
#<Location /server-status>
# SetHandler server-status
# Order allow,deny
# Allow from localhost
#</Location>
#ExtendedStatus On
# can return hits or bytes (counters)
@res = `/usr/bin/lynx -dump http://$ARGV[0]:80/server-status`;
foreach $res (@res) {
if ($res =~ /Server uptime: (.*)$/) { $up = $1; last } else { next }
if ($res =~ /Server at/) { $server = $res; last } else { next }
}
@res = `/usr/bin/lynx -dump http://$ARGV[0]:80/server-status?auto`;
foreach $res (@res) {
if ($res =~ /Total Accesses: (\d+)/) { $d1 = $1; next }
if ($res =~ /Total kBytes: (\d+)/) { $d2 = $1 * 1024; next }
}
$d1 = int($d1);
$d2 = int($d2);
#if ($ARGV[1] eq "hits") {
print "$d1\n";
# print "$d1\n";
#} elsif ($ARGV[1] eq "bytes") {
print "$d2\n";
# print "$d2\n";
#}
print "$up\n";
print "$server";

View File

@@ -1 +0,0 @@
../graphs

View File

@@ -1,10 +0,0 @@
<?php
$cpu = only_alphanumeric($_GET['cpu']);
$dir = $config['collectd_dir'] . "/" . $hostname ."/cpu-" . $cpu;
$graph = graph_collectd_cpu ($dir, $graphfile, $from, $to, $width, $height, $title, $vertical);
?>

View File

@@ -1 +0,0 @@
../rrd/

View File

@@ -0,0 +1,67 @@
<?php
unset($ports);
$ports = snmp_cache_ifIndex($device); // Cache Port List
// Build SNMP Cache Array
$etherlike_oids = array('dot3StatsAlignmentErrors', 'dot3StatsFCSErrors', 'dot3StatsSingleCollisionFrames', 'dot3StatsMultipleCollisionFrames',
'dot3StatsSQETestErrors', 'dot3StatsDeferredTransmissions', 'dot3StatsLateCollisions', 'dot3StatsExcessiveCollisions',
'dot3StatsInternalMacTransmitErrors', 'dot3StatsCarrierSenseErrors', 'dot3StatsFrameTooLongs', 'dot3StatsInternalMacReceiveErrors',
'dot3StatsSymbolErrors');
if(count($etherlike_oids) > (count($ports)*2.5)) { /// If there are 2.5x more interfaces than OIDs, do per-OID
$sub_start = utime();
echo("Caching Ports: ");
foreach($ports as $port) { echo("$port "); $array = snmp_cache_port_oids($etherlike_oids, $port, $device, $array, "EtherLike-MIB"); }
$end = utime(); $run = $end - $sub_start; $proctime = substr($run, 0, 5);
echo("\n$proctime secs\n");
} else {
$sub_start = utime();
echo("Caching Oids: ");
foreach ($etherlike_oids as $oid) { echo("$oid "); $array = snmp_cache_oid($oid, $device, $array, "EtherLike-MIB"); }
$end = utime(); $run = $end - $sub_start; $proctime = substr($run, 0, 5);
echo("\n$proctime secs\n");
}
$polled = time();
/// Loop interfaces in the DB and update where necessary
$port_query = mysql_query("SELECT * FROM `interfaces` WHERE `device_id` = '".$device['device_id']."'");
while ($port = mysql_fetch_array($port_query)) {
echo(" --> " . $port['ifDescr'] . " ");
if($array[$device[device_id]][$port[ifIndex]]) { // Check to make sure Port data is cached.
$this_port = &$array[$device[device_id]][$port[ifIndex]];
$rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/etherlike-".$port['ifIndex'].".rrd";
$rrd_create = $config['rrdtool'] . " create $rrdfile ";
$rrd_create .= "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";
if(!file_exists($rrdfile)) {
foreach($etherlike_oids as $oid){
$oid = truncate(str_replace("dot3Stats", "", $oid), 19, '');
$rrd_create .= " DS:$oid:COUNTER:600:U:100000000000";
}
shell_exec($rrd_create);
}
$rrdupdate = "N";
foreach($etherlike_oids as $oid) {
$data = $this_port[$oid] + 0;
$rrdupdate .= ":$data";
}
rrdtool_update($rrdfile, $rrdupdate);
#AlignmentErrors|FCSErrors|SingleCollisionFram|MultipleCollisionFr|SQETestErrors|DeferredTransmissio|LateCollisions|ExcessiveCollisions
#InternalMacTransmit|CarrierSenseErrors|FrameTooLongs|InternalMacReceiveE|SymbolErrors
} else {
echo("Port Deleted?"); // Port missing from SNMP cache?
}
echo("\n");
}
?>

View File

@@ -1,112 +0,0 @@
#!/usr/bin/php
<?php
include("config.php");
include("includes/functions.php");
if($argv[1]) { $where = "AND `device_id` = '$argv[1]'"; }
function snmp_cache_cip($oid, $device, $array, $mib = 0) {
global $config;
$cmd = $config['snmpbulkwalk'] . " -O snq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
if($mib) { $cmd .= "-m $mib "; }
$cmd .= $oid;
$data = trim(shell_exec($cmd));
$device_id = $device['device_id'];
echo("Caching: $oid\n");
foreach(explode("\n", $data) as $entry) {
list ($this_oid, $this_value) = split(" ", $entry);
$this_oid = trim($this_oid);
$this_value = trim($this_value);
$this_oid = substr($this_oid, 30);
list($ifIndex,$dir,$a,$b,$c,$d,$e,$f) = explode(".", $this_oid);
$h_a = zeropad(dechex($a));
$h_b = zeropad(dechex($b));
$h_c = zeropad(dechex($c));
$h_d = zeropad(dechex($d));
$h_e = zeropad(dechex($e));
$h_f = zeropad(dechex($f));
$mac = "$h_a$h_b$h_c$h_d$h_e$h_f";
if($dir == "1") { $dir = "input"; } elseif($dir == "2") { $dir = "output"; }
if($mac && $dir) {
$array[$device_id][$ifIndex][$mac][$oid][$dir] = $this_value;
}
}
return $array;
}
$i = 0;
$device_query = mysql_query("SELECT * FROM `devices` WHERE `ignore` = '0' AND `disabled` = '0' AND `status` = '1' $where ORDER BY device_id DESC");
while ($device = mysql_fetch_array($device_query)) {
echo("-> " . $device['hostname'] . "\n");
$i++;
$cip_oids = array('cipMacHCSwitchedBytes', 'cipMacHCSwitchedPkts');
foreach ($cip_oids as $oid) { $array = snmp_cache_cip($oid, $device, $array, "CISCO-IP-STAT-MIB"); }
echo("\n");
}
$mac_accounting_query = mysql_query("SELECT * FROM `mac_accounting` as A, `interfaces` AS I, `devices` AS D where A.interface_id = I.interface_id AND I.device_id = D.device_id AND D.status = '1'");
while ($acc = mysql_fetch_array($mac_accounting_query)) {
$device_id = $acc['device_id'];
$ifIndex = $acc['ifIndex'];
$mac = $acc['mac'];
if($array[$device_id][$ifIndex][$mac]) {
$b_in = $array[$device_id][$ifIndex][$mac]['cipMacHCSwitchedBytes']['input'];
$b_out = $array[$device_id][$ifIndex][$mac]['cipMacHCSwitchedBytes']['output'];
$p_in = $array[$device_id][$ifIndex][$mac]['cipMacHCSwitchedPkts']['input'];
$p_out = $array[$device_id][$ifIndex][$mac]['cipMacHCSwitchedPkts']['output'];
#echo($acc['hostname']." ".$acc['ifDescr'] . " $mac -> $b_in:$b_out:$p_in:$p_out ");
$acc_rrd = $config['rrd_dir'] . "/" . $acc['hostname'] . "/mac-accounting";
if(!is_dir($acc_rrd)) { mkdir($acc_rrd); echo("Created directory : $acc_rrd\n"); }
$old_rrdfile = $acc_rrd . "/" . $acc['ifIndex'] . "-" . $acc['ip'] . ".rrd";
$rrdfile = $acc_rrd . "/" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd";
if(is_file($old_rrdfile) && !is_file($rrdfile)) { rename($old_rrdfile, $rrdfile); echo("Moved $old_rrdfile -> $rrdfile \n"); };
$pkts_rrdfile = $acc_rrd . "/" . $acc['ifIndex'] . "-" . $acc['mac'] . "-pkts.rrd";
if(!is_file($pkts_rrdfile)) {
$woo = shell_exec($config['rrdtool'] ." create $pkts_rrdfile \
DS:IN:COUNTER:600:0:12500000000 \
DS:OUT:COUNTER: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");
}
if(!is_file($rrdfile)) {
$woo = shell_exec($config['rrdtool'] ." create $rrdfile \
DS:IN:COUNTER:600:0:12500000000 \
DS:OUT:COUNTER: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");
}
$woo = "N:".($b_in+0).":".($b_out+0);
$ret = rrdtool_update("$rrdfile", $woo);
$woo = "N:".($p_in+0).":".($p_out+0);
$ret = rrdtool_update("$pkts_rrdfile", $woo);
#echo(" R!\n");
}
}
echo("$i devices polled");
?>

View File

@@ -1,162 +0,0 @@
#!/usr/bin/php
<?php
include("config.php");
include("includes/functions.php");
if($argv[1]) { $where = "AND `device_id` = '$argv[1]'"; }
function snmp_cache($oid, $device, $array, $mib = 0) {
global $config;
$cmd = $config['snmpbulkwalk'] . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
if($mib) { $cmd .= "-m $mib "; }
$cmd .= $oid;
$data = trim(shell_exec($cmd));
$device_id = $device['device_id'];
echo("Caching: $oid\n");
foreach(explode("\n", $data) as $entry) {
list ($this_oid, $this_value) = split("=", $entry);
list ($this_oid, $this_index) = explode(".", $this_oid);
$this_index = trim($this_index);
$this_oid = trim($this_oid);
$this_value = trim($this_value);
if(!strstr($this_value, "No Such Instance currently exists at this OID") && $this_index) {
$array[$device_id][$this_index][$this_oid] = $this_value;
}
$array[$device_id][$oid] = '1';
}
return $array;
}
function snmp_cache_portIfIndex ($device, $array) {
global $config;
$cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O q -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " portIfIndex";
$output = trim(shell_exec($cmd));
echo("Caching: portIfIndex\n");
foreach(explode("\n", $output) as $entry){
$entry = str_replace("CISCO-STACK-MIB::portIfIndex.", "", $entry);
list($slotport, $ifIndex) = explode(" ", $entry);
$array[$device_id][$ifIndex]['portIfIndex'] = $slotport;
$array[$device_id][$slotport]['ifIndex'] = $ifIndex;
}
return $array;
}
function snmp_cache_portName ($device, $array) {
global $config;
$cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " portName";
$output = trim(shell_exec($cmd));
echo("Caching: portName\n");
foreach(explode("\n", $output) as $entry){
$entry = str_replace("portName.", "", $entry);
list($slotport, $portName) = explode("=", $entry);
$slotport = trim($slotport); $portName = trim($portName);
if ($array[$device_id][$slotport]['ifIndex']) {
$ifIndex = $array[$device_id][$slotport]['ifIndex'];
$array[$device_id][$slotport]['portName'] = $portName;
$array[$device_id][$ifIndex]['portName'] = $portName;
}
}
return $array;
}
$i = 0;
$device_query = mysql_query("SELECT * FROM `devices` WHERE `ignore` = '0' AND `disabled` = '0' AND `status` = '1' $where ORDER BY device_id DESC");
while ($device = mysql_fetch_array($device_query)) {
echo("-> " . $device['hostname'] . "\n");
$i++;
// Build SNMP Cache Array
$data_oids = array('ifName','ifDescr','ifAlias', 'ifAdminStatus', 'ifOperStatus', 'ifMtu', 'ifSpeed', 'ifHighSpeed', 'ifType', 'ifPhysAddress',
'ifPromiscuousMode','ifConnectorPresent');
$stat_oids = array('ifHCInOctets', 'ifHCOutOctets', 'ifInErrors', 'ifOutErrors', 'ifInUcastPkts', 'ifOutUcastPkts', 'ifInNUcastPkts', 'ifOutNUcastPkts',
'ifHCInMulticastPkts', 'ifHCInBroadcastPkts', 'ifHCOutMulticastPkts', 'ifHCOutBroadcastPkts');
$etherlike_oids = array('dot3StatsAlignmentErrors', 'dot3StatsFCSErrors', 'dot3StatsSingleCollisionFrames', 'dot3StatsMultipleCollisionFrames',
'dot3StatsSQETestErrors', 'dot3StatsDeferredTransmissions', 'dot3StatsLateCollisions', 'dot3StatsExcessiveCollisions',
'dot3StatsInternalMacTransmitErrors', 'dot3StatsCarrierSenseErrors', 'dot3StatsFrameTooLongs', 'dot3StatsInternalMacReceiveErrors',
'dot3StatsSymbolErrors', 'dot3StatsDuplexStatus');
$cisco_oids = array('locIfHardType', 'locIfInRunts', 'locIfInGiants', 'locIfInCRC', 'locIfInFrame', 'locIfInOverrun', 'locIfInIgnored', 'locIfInAbort',
'locIfCollisions', 'locIfInputQueueDrops', 'locIfOutputQueueDrops');
$pagp_oids = array('pagpOperationMode', 'pagpPortState', 'pagpPartnerDeviceId', 'pagpPartnerLearnMethod', 'pagpPartnerIfIndex', 'pagpPartnerGroupIfIndex',
'pagpPartnerDeviceName', 'pagpEthcOperationMode', 'pagpDeviceId', 'pagpGroupIfIndex');
$cip_oids = array('cipMacHCSwitchedBytes', 'cipMacHCSwitchedBytes', 'cipMacHCSwitchedPkts', 'cipMacHCSwitchedPkts');
$array = snmp_cache_portIfIndex ($device, $array);
$array = snmp_cache_portName ($device, $array);
foreach ($data_oids as $oid) { $array = snmp_cache($oid, $device, $array, "IF-MIB"); }
#foreach ($cip_oids as $oid) { $array = snmp_cache($oid, $device, $array, "CISCO-IP-STAT-MIB"); }
foreach ($stat_oids as $oid) { $array = snmp_cache($oid, $device, $array, "IF-MIB"); }
foreach ($etherlike_oids as $oid) { $array = snmp_cache($oid, $device, $array, "EtherLike-MIB"); }
foreach ($cisco_oids as $oid) { $array = snmp_cache($oid, $device, $array, "OLD-CISCO-INTERFACES-MIB"); }
foreach ($pagp_oids as $oid) { $array = snmp_cache($oid, $device, $array, "CISCO-PAGP-MIB"); }
snmp_cache("vmVlan", $device, $array, "CISCO-VLAN-MEMBERSHIP-MIB");
snmp_cache("vlanTrunkPortEncapsulationOperType", $device, $array, "CISCO-VTP-MIB");
snmp_cache("vlanTrunkPortNativeVlan", $device, $array, "CISCO-VTP-MIB");
// End Building SNMP Cache Array
// New interface detection
///// TO DO
// End New interface detection
// Loop interfaces in the DB and update where necessary
$port_query = mysql_query("SELECT * FROM `interfaces` WHERE `device_id` = '".$device['device_id']."'");
while ($port = mysql_fetch_array($port_query)) {
echo(" --> " . $port['ifDescr'] . " ");
if($array[$device[device_id]][$port[ifIndex]]) { // Check to make sure Port data is cached.
$this_port = $array[$device[device_id]][$port[ifIndex]];
/// Update IF-MIB
foreach ($data_oids as $oid) {
if ( $port[$oid] != $this_port[$oid]) {
$update .= $separator . "`$oid` = '".$this_port[$oid]."'";
$separator = ", ";
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $port['device_id'] . "', '" . $port['interface_id'] . "', NOW(), '".$oid . ": ".$port[$oid]." -> " . $this_port[$oid]."')");
#eventlog($device['device_id'], 'interface', $port['interface_id'], $oid . ": ".$port[$oid]." -> " . $this_port[$oid]);
echo($oid . " ");
}
}
/// End Update IF-MIB
/// Update PAgP
if($this_port['pagpOperationMode']) {
unset($separator); unset($update);
foreach ($pagp_oids as $oid) { // Loop the OIDs
if ( $this_port[$oid] != $port[$oid] ) { // If data has changed, build a query
$update .= $separator . "`$oid` = '".$this_port[$oid]."'";
$separator = ", ";
echo("PAgP ");
}
}
}
// End Update PAgP
if ($update) { /// Do Updates
$update_query = "UPDATE `interfaces` SET ";
$update_query .= $update;
$update_query .= " WHERE `interface_id` = '" . $port['interface_id'] . "'";
#@mysql_query($update_query);
#echo("$update_query");
if(mysql_affected_rows > '0') { echo("Updated "); }
} /// End Updates
unset($separator); unset($update_query); unset($update);
} else {
echo("Port Deleted?"); // Port missing from SNMP cache?
}
echo("\n");
}
#unset($array);
echo("\n");
}
echo("$i devices polled");
?>

View File

@@ -1,23 +0,0 @@
#!/usr/bin/php
### Purge deleted interfaces from the database
<?php
include("config.php");
include("includes/functions.php");
$query = mysql_query("SELECT * FROM interfaces AS I, devices as D WHERE I.device_id = D.device_id AND I.deleted = '1'");
while($interface = mysql_fetch_array($query)) {
mysql_query("DELETE from interfaces where interface_id = '" . $interface['interface_id'] . "'");
mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '" . $interface['interface_id'] . "'");
mysql_query("DELETE from `links` WHERE `src_if` = '" . $interface['interface_id'] . "'");
mysql_query("DELETE from `links` WHERE `dst_if` = '" . $interface['interface_id'] . "'");
mysql_query("DELETE from `ipaddr` WHERE `interface_id` = '" . $interface['interface_id'] . "'");
echo("Removed interface " . $interface['ifDescr'] . " from " . $interface['hostname'] . "\n");
}
?>