correctly escape : for temperatures so FPC temperature works on junos + add safename() function to strip unwanted characters from filenames - should not break anything existing afaik

git-svn-id: http://www.observium.org/svn/observer/trunk@765 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2010-02-05 22:10:06 +00:00
parent e644b9d2dd
commit 57a9689ddd
46 changed files with 66 additions and 65 deletions
+4
View File
@@ -74,6 +74,10 @@ function gethostosbyid($id) {
return $result;
}
function safename($name)
{
return preg_replace('/[^a-zA-Z0-9,._\+\()\-]/', '_', $name);
}
?>
+1 -1
View File
@@ -2,7 +2,7 @@
echo("Collecting Apache statistics...");
$apacherrd = "rrd/" . $device['hostname'] . "-apache.rrd";
$apacherrd = "rrd/" . safename($device['hostname'] . "-apache.rrd");
if(!is_file($apacherrd)) {
$woo= `rrdtool create $apacherrd \
DS:bits:COUNTER:600:U:10000000 \
+2 -2
View File
@@ -91,7 +91,7 @@ if ($device['os'] == "junos")
}
}
$peerrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/bgp-" . $peer['bgpPeerIdentifier'] . ".rrd";
$peerrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("bgp-" . $peer['bgpPeerIdentifier'] . ".rrd");
if(!is_file($peerrrd)) {
$woo = shell_exec($config['rrdtool'] . " create $peerrrd \
DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 \
@@ -153,7 +153,7 @@ if ($device['os'] == "junos")
mysql_query($update);
$cbgp_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/cbgp-" . $peer['bgpPeerIdentifier'] . ".$afi.$safi.rrd";
$cbgp_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cbgp-" . $peer['bgpPeerIdentifier'] . ".$afi.$safi.rrd");
if(!is_file($cbgp_rrd)) {
$woo = shell_exec($config['rrdtool'] . " create $cbgp_rrd \
DS:AcceptedPrefixes:GAUGE:600:U:100000000000 \
@@ -25,7 +25,7 @@ while($mempool = mysql_fetch_array($pool_data)) {
echo(round(($cempMemPoolUsed/($cempMemPoolFree+$cempMemPoolUsed))*100) . "% ");
$poolrrd = addslashes($config['rrd_dir'] . "/" . $device['hostname'] . "/cempMemPool-" . $oid . ".rrd");
$poolrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cempMemPool-" . $oid . ".rrd");
if (!is_file($poolrrd)) {
`rrdtool create $poolrrd \
@@ -17,7 +17,7 @@ while($sensor = mysql_fetch_array($sensors)) {
list($entSensorValue, $entSensorStatus) = explode("\n", $sensor_data);
$rrd = addslashes($config['rrd_dir'] . "/" . $device['hostname'] . "/ces-" . $oid . ".rrd");
$rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("ces-" . $oid . ".rrd");
if (!is_file($rrd)) {
`rrdtool create $rrd \
@@ -50,7 +50,7 @@ while ($acc = mysql_fetch_array($mac_accounting_query)) {
}
if($debug) {echo("\n" . $acc['hostname']." ".$acc['ifDescr'] . " $mac -> $b_in:$b_out:$p_in:$p_out ");}
$rrdfile = $host_rrd . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd";
$rrdfile = $host_rrd . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd");
if(!is_file($rrdfile)) {
$woo = shell_exec($config['rrdtool'] ." create $rrdfile \
+1 -1
View File
@@ -20,7 +20,7 @@ while($mempool = mysql_fetch_array($pool_data)) {
echo(round(($cmpUsed/($cmpFree+$cmpUsed))*100) . "% ");
$poolrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/cmp-" . $mempool['Index'] . ".rrd";
$poolrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cmp-" . $mempool['Index'] . ".rrd");
if (!is_file($poolrrd)) {
shell_exec ($config['rrdtool'] . " create $poolrrd \
+1 -1
View File
@@ -30,7 +30,7 @@ if($device['os_group'] == "ios") {
echo(" --> " . $port['ifDescr'] . " POE");
/// Update RRDs
$rrdfile = $host_rrd . "/" . $port['ifIndex'] . ".rrd";
$rrdfile = $host_rrd . "/" . safename($port['ifIndex'] . ".rrd");
if(!is_file($rrdfile)) {
$woo = shell_exec($config['rrdtool'] . " create $rrdfile -s 300 \
DS:PortPwrAllocated:GAUGE:600:0:12500000000 \
+1 -1
View File
@@ -9,7 +9,7 @@ while($processor = mysql_fetch_array($proc_data)) {
echo("Checking CPU " . $processor['entPhysicalDescr'] . "... ");
$procrrd = addslashes($config['rrd_dir'] . "/" . $device['hostname'] . "/cpmCPU-" . $processor['cpmCPU_oid'] . ".rrd");
$procrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cpmCPU-" . $processor['cpmCPU_oid'] . ".rrd");
if (!is_file($procrrd)) {
`rrdtool create $procrrd \
+1 -1
View File
@@ -35,7 +35,7 @@ if($device[os] != "Snom") {
foreach($protos as $proto) {
unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
$rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-".$proto.".rrd";
$rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("netstats-".$proto.".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 \
+1 -1
View File
@@ -18,7 +18,7 @@ while ($hrDevice = mysql_fetch_array($query)) {
$update_query .= " WHERE hrDevice_id = '".$hrDevice['hrDevice_id']."'";
@mysql_query($update_query); $mysql++; echo(".");
$procrrd = addslashes($config['rrd_dir'] . "/" . $device['hostname'] . "/hrProcessor-" . $hrDevice['hrDeviceIndex'] . ".rrd");
$procrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("hrProcessor-" . $hrDevice['hrDeviceIndex'] . ".rrd");
if (!is_file($procrrd)) {
shell_exec($config['rrdtool'] . " create $procrrd \
+2 -2
View File
@@ -13,8 +13,8 @@ while ($dr = mysql_fetch_array($dq)) {
$used = $used_units * $hrStorageAllocationUnits;
$perc = round($used / $hrStorageSize * 100, 2);
$filedesc = str_replace("\"", "", str_replace("/", "_", $hrStorageDescr));
$old_storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/storage-" . $filedesc . ".rrd";
$storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/hrStorage-" . $hrStorageIndex . ".rrd";
$old_storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("storage-" . $filedesc . ".rrd");
$storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("hrStorage-" . $hrStorageIndex . ".rrd");
if(is_file($old_storage_rrd)) { rename($old_storage_rrd,$storage_rrd); }
if (!is_file($storage_rrd)) {
shell_exec($config['rrdtool'] . " create $storage_rrd \
+1 -1
View File
@@ -61,7 +61,7 @@ while ($interface = mysql_fetch_array($interface_query)) {
if($config[ifname][$device[os]]) { $ifDescr = $ifName; }
$rrdfile = $host_rrd . "/" . $interface['ifIndex'] . ".rrd";
$rrdfile = $host_rrd . "/" . safename($interface['ifIndex'] . ".rrd");
if(!is_file($rrdfile)) {
$woo = shell_exec($config['rrdtool'] . " create $rrdfile \
+1 -1
View File
@@ -23,7 +23,7 @@
unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
$rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/ipSystemStats-".$af.".rrd";
$rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("ipSystemStats-".$af.".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";
+1 -1
View File
@@ -4,7 +4,7 @@
$this_port = &$array[$device[device_id]][$port[ifIndex]];
$rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/etherlike-".$port['ifIndex'].".rrd";
$rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("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 \
+1 -1
View File
@@ -107,7 +107,7 @@
}
/// Update RRDs
$rrdfile = $host_rrd . "/" . $port['ifIndex'] . ".rrd";
$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 \
+2 -3
View File
@@ -20,9 +20,7 @@ while($temperature = mysql_fetch_array($temp_data)) {
if ($temp != 999.9) break; # TME sometimes sends 999.9 when it is right in the middle of an update;
}
$temprrd = addslashes($config['rrd_dir'] . "/" . $device['hostname'] . "/temp-" . str_replace("/", "_", str_replace(" ", "_",$temperature['temp_descr'])) . ".rrd");
$temprrd = str_replace(")", "_", $temprrd);
$temprrd = str_replace("(", "_", $temprrd);
$temprrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temp-" . $temperature['temp_descr'] . ".rrd");
if (!is_file($temprrd)) {
`rrdtool create $temprrd \
@@ -38,6 +36,7 @@ while($temperature = mysql_fetch_array($temp_data)) {
$updatecmd = "rrdtool update $temprrd N:$temp";
if ($debug) { echo "$updatecmd\n"; }
shell_exec($updatecmd);
if($temperature['temp_current'] < $temperature['temp_limit'] && $temp >= $temperature['temp_limit']) {