Remove all unneeded if($debug)-statements and replace them with d_echo

This commit is contained in:
Mark Schouten
2015-08-20 15:02:40 +02:00
parent e0edeab13f
commit 55a2e0423d
24 changed files with 47 additions and 142 deletions

View File

@@ -1,9 +1,7 @@
<?php
$sql = "SELECT * FROM `applications` WHERE `device_id` = '".$device['device_id']."'";
if ($debug) {
echo $sql."\n";
}
d_echo($sql."\n");
$app_rows = dbFetchRows('SELECT * FROM `applications` WHERE `device_id` = ?', array($device['device_id']));

View File

@@ -1,8 +1,5 @@
<?php
// We should walk, so we can discover here too.
global $debug;
if ($config['enable_bgp']) {
foreach (dbFetchRows('SELECT * FROM bgpPeers WHERE device_id = ?', array($device['device_id'])) as $peer) {
// Poll BGP Peer
@@ -105,16 +102,12 @@ if ($config['enable_bgp']) {
$peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip];
$peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip];
$peer_cmd .= '|grep -v "No Such Instance"';
if ($debug) {
echo "\n$peer_cmd\n";
}
d_echo("\n$peer_cmd\n");
$peer_data = trim(`$peer_cmd`);
list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
if ($debug) {
echo "State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n";
}
d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n");
$bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr));
if ($bgpLocalAddr == '00000000000000000000000000000000') {
@@ -175,9 +168,7 @@ if ($config['enable_bgp']) {
foreach ($peer_afis as $peer_afi) {
$afi = $peer_afi['afi'];
$safi = $peer_afi['safi'];
if ($debug) {
echo "$afi $safi\n";
}
d_echo("$afi $safi\n");
if ($device['os_group'] == 'cisco') {
$bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']);
@@ -230,9 +221,7 @@ if ($config['enable_bgp']) {
$cbgp_data .= "$v\n";
}
if ($debug) {
echo "$cbgp_data\n";
}
d_echo("$cbgp_data\n");
}
else {
// FIXME - move to function
@@ -246,15 +235,11 @@ if ($config['enable_bgp']) {
$cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
$cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
if ($debug) {
echo "$cbgp_cmd\n";
}
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);
if ($debug) {
echo "$cbgp_data\n";
}
d_echo("$cbgp_data\n");
}//end if
list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data);
}//end if

View File

@@ -13,9 +13,7 @@ if ($device['os_group'] == 'cisco') {
$cefs_db[$cef_id] = $ceftmp['cef_switching_id'];
}
if ($debug) {
print_r($cefs);
}
d_echo($cefs);
if (is_array($cefs)) {
if (!is_array($entity_array)) {

View File

@@ -53,16 +53,12 @@ if ($device['os_group'] == 'cisco') {
$oid_rate = ($oid_diff / $polled_period);
$acc['update'][$oid_dir.'_rate'] = $oid_rate;
$acc['update'][$oid_dir.'_delta'] = $oid_diff;
if ($debug) {
echo "\n $oid_dir ($oid_diff B) $oid_rate Bps $polled_period secs\n";
}
d_echo("\n $oid_dir ($oid_diff B) $oid_rate Bps $polled_period secs\n");
}
}
}
if ($debug) {
echo "\n".$acc['hostname'].' '.$acc['ifDescr']." $mac -> $b_in:$b_out:$p_in:$p_out ";
}
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');

View File

@@ -32,9 +32,7 @@ if ($device['os'] == 'ios') {
$rrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('c6kxbar-'.$index.'-'.$subindex.'.rrd');
if ($debug) {
echo "$rrd ";
}
d_echo("$rrd ");
if (!is_file($rrd)) {
rrdtool_create(

View File

@@ -23,9 +23,7 @@ function poll_sensor($device, $class, $unit) {
else {
// Try 5 times to get a valid temp reading
for ($i = 0; $i < 5; $i++) {
if ($debug) {
echo "Attempt $i ";
}
d_echo("Attempt $i ");
$sensor_value = trim(str_replace('"', '', snmp_get($device, $sensor['sensor_oid'], '-OUqnv', "SNMPv2-MIB$mib")));
preg_match('/[\d\.]+/', $sensor_value, $temp_response);
@@ -280,9 +278,7 @@ function poll_device($device, $options) {
// echo("$device_end - $device_start; $device_time $device_run");
echo "Polled in $device_time seconds\n";
if ($debug) {
echo 'Updating '.$device['hostname'].' - '.print_r($update_array)." \n";
}
d_echo('Updating '.$device['hostname'].' - '.print_r($update_array)." \n");
$updated = dbUpdate($update_array, 'devices', '`device_id` = ?', array($device['device_id']));
if ($updated) {

View File

@@ -20,9 +20,7 @@ if (count($vp_rows)) {
$oid = $vp['ifIndex'].'.'.$vp['vp_id'];
if ($debug) {
echo "$oid ";
}
d_echo("$oid ");
$t_vp = $vp_cache[$oid];
@@ -33,9 +31,7 @@ if (count($vp_rows)) {
$rrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('vp-'.$vp['ifIndex'].'-'.$vp['vp_id'].'.rrd');
if ($debug) {
echo "$rrd ";
}
d_echo("$rrd ");
if (!is_file($rrd)) {
rrdtool_create(

View File

@@ -44,9 +44,7 @@ foreach (dbFetchRows('SELECT * FROM mempools WHERE device_id = ?', array($device
}
if ($config['memcached']['enable'] === true) {
if ($debug) {
print_r($mempool['state']);
}
d_echo($mempool['state']);
$memcache->set('mempool-'.$mempool['mempool_id'].'-value', $mempool['state']);
}

View File

@@ -7,9 +7,7 @@ $pool_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-ENHANCED-MEM
$pool_cmd .= " cempMemPoolUsed.$oid cempMemPoolFree.$oid cempMemPoolLargestFree.$oid";
$pool_cmd .= " | cut -f 1 -d ' '";
if ($debug) {
echo "SNMP [ $pool_cmd ]\n";
}
d_echo("SNMP [ $pool_cmd ]\n");
$pool = shell_exec($pool_cmd);

View File

@@ -7,9 +7,7 @@ $pool_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-MEMORY-POOL-
$pool_cmd .= " ciscoMemoryPoolUsed.$oid ciscoMemoryPoolFree.$oid ciscoMemoryPoolLargestFree.$oid";
$pool_cmd .= " | cut -f 1 -d ' '";
if ($debug) {
echo "$pool_cmd";
}
d_echo("$pool_cmd");
$pool = shell_exec($pool_cmd);

View File

@@ -9,14 +9,10 @@
// NETSWITCH-MIB::hpGlobalMemAllocBytes.1 = INTEGER: 1668728
if (!is_array($mempool_cache['hpGlobal'])) {
$mempool_cache['hpGlobal'] = snmpwalk_cache_oid($device, 'hpGlobal', null, 'NETSWITCH-MIB', $config['mibdir'].':'.$config['mibdir'].'/hp');
if ($debug) {
print_r($mempool_cache);
}
d_echo($mempool_cache);
}
else {
if ($debug) {
echo 'Cached!';
}
d_echo('Cached!');
}
$entry = $mempool_cache['hpGlobal'][$mempool[mempool_index]];

View File

@@ -9,14 +9,10 @@
// NETSWITCH-MIB::hpLocalMemAllocBytes.1 = INTEGER: 1668728
if (!is_array($mempool_cache['hpLocal'])) {
$mempool_cache['hpLocal'] = snmpwalk_cache_oid($device, 'hpLocal', null, 'NETSWITCH-MIB', $config['mibdir'].':'.$config['mibdir'].'/hp');
if ($debug) {
print_r($mempool_cache);
}
d_echo($mempool_cache);
}
else {
if ($debug) {
echo 'Cached!';
}
d_echo('Cached!');
}
$entry = $mempool_cache['hpLocal'][$mempool[mempool_index]];

View File

@@ -3,14 +3,10 @@
// HOST-RESOURCES-MIB - Memory Objects
if (!is_array($storage_cache['hrstorage'])) {
$storage_cache['hrstorage'] = snmpwalk_cache_oid($device, 'hrStorageEntry', null, 'HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES');
if ($debug) {
print_r($storage_cache);
}
d_echo($storage_cache);
}
else {
if ($debug) {
echo 'Cached!';
}
d_echo('Cached!');
}
$entry = $storage_cache['hrstorage'][$mempool[mempool_index]];

View File

@@ -2,22 +2,16 @@
$oid = $mempool['mempool_index'];
if ($debug) {
echo 'JunOS Mempool';
}
d_echo('JunOS Mempool');
if (!is_array($mempool_cache['junos'])) {
if ($debug) {
echo 'caching';
}
d_echo('caching');
$mempool_cache['junos'] = array();
$mempool_cache['junos'] = snmpwalk_cache_multi_oid($device, 'jnxOperatingBuffer', $mempool_cache['junos'], 'JUNIPER-MIB', $config['install_dir'].'/mibs/junos');
$mempool_cache['junos'] = snmpwalk_cache_multi_oid($device, 'jnxOperatingDRAMSize', $mempool_cache['junos'], 'JUNIPER-MIB', $config['install_dir'].'/mibs/junos');
$mempool_cache['junos'] = snmpwalk_cache_multi_oid($device, 'jnxOperatingMemory', $mempool_cache['junos'], 'JUNIPER-MIB', $config['install_dir'].'/mibs/junos');
if ($debug) {
print_r($mempool_cache);
}
d_echo($mempool_cache);
}
$entry = $mempool_cache['junos'][$mempool[mempool_index]];

View File

@@ -2,21 +2,15 @@
$oid = $mempool['mempool_index'];
if ($debug) {
echo 'Huawei VRP Mempool';
}
d_echo('Huawei VRP Mempool');
if (!is_array($mempool_cache['vrp'])) {
if ($debug) {
echo 'caching';
}
d_echo('caching');
$mempool_cache['vrp'] = array();
$mempool_cache['vrp'] = snmpwalk_cache_multi_oid($device, 'hwEntityMemSize', $mempool_cache['vrp'], 'HUAWEI-ENTITY-EXTENT-MIB', $config['install_dir'].'/mibs');
$mempool_cache['vrp'] = snmpwalk_cache_multi_oid($device, 'hwEntityMemUsage', $mempool_cache['vrp'], 'HUAWEI-ENTITY-EXTENT-MIB', $config['install_dir'].'/mibs');
if ($debug) {
print_r($mempool_cache);
}
d_echo($mempool_cache);
}
$entry = $mempool_cache['vrp'][$mempool[mempool_index]];

View File

@@ -77,9 +77,7 @@ if ($device['os'] == 'netscaler') {
print_r($vsvr);
}
if ($debug) {
print_r($vsvrs);
}
d_echo($vsvrs);
foreach ($vsvr_array as $index => $vsvr) {
if (isset($vsvr['vsvrName'])) {
@@ -129,9 +127,7 @@ if ($device['os'] == 'netscaler') {
}//end if
}//end foreach
if ($debug) {
print_r($vsvr_exist);
}
d_echo($vsvr_exist);
foreach ($vsvrs as $db_name => $db_id) {
if (!$vsvr_exist[$db_name]) {

View File

@@ -327,9 +327,7 @@ if (is_array($ospf_nbrs_db)) {
foreach ($ospf_nbr_oids as $oid) {
// Loop the OIDs
if ($debug) {
echo $ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]."\n";
}
d_echo($ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]."\n");
if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid]) {
// If data has changed, build a query

View File

@@ -192,9 +192,7 @@ else {
$polled = time();
// End Building SNMP Cache Array
if ($debug) {
print_r($port_stats);
}
d_echo($port_stats);
// Build array of ports in the database
// FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :>
@@ -243,9 +241,7 @@ foreach ($ports as $port) {
if ($config['memcached']['enable'] === true) {
$state = $memcache->get('port-'.$port['port_id'].'-state');
if ($debug) {
print_r($state);
}
d_echo($state);
if (is_array($state)) {
$port = array_merge($port, $state);
@@ -336,7 +332,7 @@ foreach ($ports as $port) {
$port['update'][$oid] = array('NULL');
log_event($oid.': '.$port[$oid].' -> NULL', $device, 'interface', $port['port_id']);
if ($debug) {
echo $oid.': '.$port[$oid].' -> NULL ';
d_echo($oid.': '.$port[$oid].' -> NULL ');
}
else {
echo $oid.' ';
@@ -346,7 +342,7 @@ foreach ($ports as $port) {
$port['update'][$oid] = $this_port[$oid];
log_event($oid.': '.$port[$oid].' -> '.$this_port[$oid], $device, 'interface', $port['port_id']);
if ($debug) {
echo $oid.': '.$port[$oid].' -> '.$this_port[$oid].' ';
d_echo($oid.': '.$port[$oid].' -> '.$this_port[$oid].' ');
}
else {
echo $oid.' ';
@@ -423,9 +419,7 @@ foreach ($ports as $port) {
$port['state'][$oid.'_delta'] = $oid_diff;
}
if ($debug) {
echo "\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n";
}
d_echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n");
}//end if
}//end foreach
@@ -547,9 +541,7 @@ foreach ($ports as $port) {
// Update Memcached
if ($config['memcached']['enable'] === true) {
if ($debug) {
print_r($port['state']);
}
d_echo($port['state']);
$memcache->set('port-'.$port['port_id'].'-state', $port['state']);
}
@@ -563,9 +555,7 @@ foreach ($ports as $port) {
// Update Database
if (count($port['update'])) {
$updated = dbUpdate($port['update'], 'ports', '`port_id` = ?', array($port['port_id']));
if ($debug) {
echo "$updated updated";
}
d_echo("$updated updated");
}
// End Update Database

View File

@@ -19,9 +19,7 @@ foreach (dbFetchRows('SELECT * FROM storage WHERE device_id = ?', array($device[
// FIXME Generic poller goes here if we ever have a discovery module which uses it.
}
if ($debug) {
print_r($storage);
}
d_echo($storage);
if ($storage['size']) {
$percent = round(($storage['used'] / $storage['size'] * 100));

View File

@@ -3,9 +3,7 @@
// HOST-RESOURCES-MIB - Storage Objects
if (!is_array($storage_cache['hrstorage'])) {
$storage_cache['hrstorage'] = snmpwalk_cache_oid($device, 'hrStorageEntry', null, 'HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES');
if ($debug) {
print_r($storage_cache);
}
d_echo($storage_cache);
}
$entry = $storage_cache['hrstorage'][$storage[storage_index]];

View File

@@ -2,9 +2,7 @@
if (!is_array($storage_cache['netapp-storage'])) {
$storage_cache['netapp-storage'] = snmpwalk_cache_oid($device, 'dfEntry', null, 'NETAPP-MIB');
if ($debug) {
print_r($storage_cache);
}
d_echo($storage_cache);
}
$entry = $storage_cache['netapp-storage'][$storage[storage_index]];

View File

@@ -15,15 +15,11 @@ if (count($diskio_data)) {
echo $diskio['diskio_descr'].' ';
if ($debug) {
print_r($entry);
}
d_echo($entry);
$rrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('ucd_diskio-'.$diskio['diskio_descr'].'.rrd');
if ($debug) {
echo "$rrd ";
}
d_echo("$rrd ");
if (!is_file($rrd)) {
rrdtool_create(

View File

@@ -1,7 +1,5 @@
<?php
global $debug;
if ($device['os_group'] == 'unix') {
echo $config['project_name'].' UNIX Agent: ';

View File

@@ -3,9 +3,7 @@
// Plugins
if (!empty($agent_data['munin'])) {
echo 'Munin Plugins:';
if ($debug) {
print_r($agent_data['munin']);
}
d_echo($agent_data['munin']);
// Build array of existing plugins
$plugins_dbq = dbFetchRows('SELECT * FROM `munin_plugins` WHERE `device_id` = ?', array($device['device_id']));
@@ -38,9 +36,7 @@ if (!empty($agent_data['munin'])) {
$plugin_rrd = $plugins_rrd_dir.'/'.$plugin_type;
$plugin_uniq = $plugin_type.'_';
// }
if ($debug) {
echo "\n[$plugin_data]\n";
}
d_echo("\n[$plugin_data]\n");
foreach (explode("\n", $plugin_data) as $line) {
list($key, $value) = explode(' ', $line, 2);