Fix coding style part 2

This commit is contained in:
Job Snijders
2015-07-13 20:10:26 +02:00
parent ad9590df9b
commit d8693f05ae
733 changed files with 37359 additions and 33947 deletions

View File

@@ -1,138 +1,142 @@
#!/usr/bin/env php
<?php
include('../includes/console_colour.php');
include('../includes/console_table.php');
include("../includes/defaults.inc.php");
include("../config.php");
include_once("../includes/definitions.inc.php");
include("../includes/functions.php");
include("../html/includes/functions.inc.php");
require '../includes/console_colour.php';
require '../includes/console_table.php';
require '../includes/defaults.inc.php';
require '../config.php';
require_once '../includes/definitions.inc.php';
require '../includes/functions.php';
require '../html/includes/functions.inc.php';
$console_color = new Console_Color2();
$long_opts = array('list::','device-stats');
$options = getopt("l:d:",$long_opts);
$long_opts = array(
'list::',
'device-stats',
);
$options = getopt('l:d:', $long_opts);
$end = 0;
while($end == 0)
{
passthru('clear');
$tbl = new Console_Table(CONSOLE_TABLE_ALIGN_RIGHT);
foreach (dbFetchRows("SELECT * FROM `devices` ORDER BY `hostname`") as $device)
{
if (get_dev_attrib($device,'override_sysLocation_bool'))
{
$device['real_location'] = $device['location'];
$device['location'] = get_dev_attrib($device,'override_sysLocation_string');
while ($end == 0) {
passthru('clear');
$tbl = new Console_Table(CONSOLE_TABLE_ALIGN_RIGHT);
foreach (dbFetchRows('SELECT * FROM `devices` ORDER BY `hostname`') as $device) {
if (get_dev_attrib($device, 'override_sysLocation_bool')) {
$device['real_location'] = $device['location'];
$device['location'] = get_dev_attrib($device, 'override_sysLocation_string');
}
$devices['count']++;
$cache['devices']['hostname'][$device['hostname']] = $device['device_id'];
$cache['devices']['id'][$device['device_id']] = $device;
$cache['device_types'][$device['type']]++;
}
$devices['count']++;
// Include the required SQL queries to get our data
include '../includes/db/status_count.inc.php';
$cache['devices']['hostname'][$device['hostname']] = $device['device_id'];
$cache['devices']['id'][$device['device_id']] = $device;
$tbl->addRow(array('Devices ('.$devices['count'].')', print $console_color->convert('%g'.$devices['up'].' Up%n'), print $console_color->convert('%r'.$devices['down'].' Down%n'), print $console_color->convert('%y'.$devices['ignored'].' Ignored%n'), print $console_color->convert('%p'.$devices['disabled'].' Disabled%n')));
$tbl->addRow(array('Ports ('.$ports['count'].')', print $console_color->convert('%g'.$ports['up'].' Up%n'), print $console_color->convert('%r'.$ports['down'].' Down%n'), print $console_color->convert('%y'.$ports['ignored'].' Ignored%n'), print $console_color->convert('%p'.$ports['shutdown'].' Shutdown%n')));
$tbl->addRow(array('Services ('.$services['count'].')', print $console_color->convert('%g'.$services['up'].' Up%n'), print $console_color->convert('%r'.$services['down'].' Down%n'), print $console_color->convert('%y'.$services['ignored'].' Ignored%n'), print $console_color->convert('%p'.$services['disabled'].' Shutdown%n')));
$cache['device_types'][$device['type']]++;
}
// Include the required SQL queries to get our data
require('../includes/db/status_count.inc.php');
$tbl->addRow(array('Devices ('.$devices['count'].')',print $console_color->convert("%g".$devices['up']." Up%n"),print $console_color->convert("%r".$devices['down']." Down%n"),print $console_color->convert("%y".$devices['ignored']." Ignored%n"),print $console_color->convert("%p".$devices['disabled']." Disabled%n")));
$tbl->addRow(array('Ports ('.$ports['count'].')',print $console_color->convert("%g".$ports['up']." Up%n"),print $console_color->convert("%r".$ports['down']." Down%n"),print $console_color->convert("%y".$ports['ignored']." Ignored%n"),print $console_color->convert("%p".$ports['shutdown']." Shutdown%n")));
$tbl->addRow(array('Services ('.$services['count'].')',print $console_color->convert("%g".$services['up']." Up%n"),print $console_color->convert("%r".$services['down']." Down%n"),print $console_color->convert("%y".$services['ignored']." Ignored%n"),print $console_color->convert("%p".$services['disabled']." Shutdown%n")));
echo $tbl->getTable();
if($options['l'] == 'eventlog')
{
$tbl = new Console_Table();
$tbl->setHeaders(array('Date time','Host','Message','Type','Reference'));
if(is_numeric($options['d']))
{
$sql = "WHERE host='".$options['d']."'";
}
$query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E $sql ORDER BY `datetime` DESC LIMIT 20";
foreach (dbFetchRows($query, $param) as $entry)
{
$tbl->addRow(array($entry['datetime'],gethostbyid($entry['host']),$entry['message'],$entry['type'],$entry['reference']));
}
echo $tbl->getTable();
}
elseif($options['l'] == 'syslog')
{
$tbl = new Console_Table();
$tbl->setHeaders(array('Date time','Host','Program','Message','Level','Facility'));
if(is_numeric($options['d']))
{
$sql = "WHERE device_id='".$options['d']."'";
}
$query = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog AS S $sql_query ORDER BY `timestamp` DESC LIMIT 20";
foreach (dbFetchRows($query, $param) as $entry)
{
$tbl->addRow(array($entry['timestamp'],gethostbyid($entry['device_id']),$entry['program'],$entry['msg'],$entry['level'],$entry['facility']));
}
echo $tbl->getTable();
}
elseif($options['list'] == 'devices')
{
$tbl = new Console_Table();
$tbl->setHeaders(array('Device ID','Device Hostname'));
$query = "SELECT device_id,hostname FROM `devices` ORDER BY hostname";
foreach (dbFetchRows($query, $sql_param) as $device)
{
$tbl->addRow(array($device['device_id'],$device['hostname']));
}
echo $tbl->getTable();
exit;
}
elseif(isset($options['device-stats']))
{
$tbl = new Console_Table();
$tbl->setHeaders(array('Port name','Status','IPv4 Address','Speed In','Speed Out','Packets In','Packets Out','Speed','Duplex','Type','MAC Address','MTU'));
foreach (dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ?", array($options['d'])) as $port)
{
if($port['ifOperStatus'] == 'up')
{
$port['in_rate'] = $port['ifInOctets_rate'] * 8;
$port['out_rate'] = $port['ifOutOctets_rate'] * 8;
$in_perc = @round($port['in_rate']/$port['ifSpeed']*100);
$out_perc = @round($port['in_rate']/$port['ifSpeed']*100);
}
if ($port['ifSpeed']) { $port_speed = humanspeed($port['ifSpeed']); }
if ($port[ifDuplex] != "unknown") { $port_duplex = $port['ifDuplex']; }
if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != "") { $port_mac = formatMac($port['ifPhysAddress']); }
if ($port['ifMtu'] && $port['ifMtu'] != "") { $port_mtu = $port['ifMtu']; }
$tbl->addRow(array($port['ifDescr'],$port['ifOperStatus'],'',formatRates($port['in_rate']),formatRates($port['out_rate']),format_bi($port['ifInUcastPkts_rate']).'pps',format_bi($port['ifOutUcastPkts_rate']).'pps',$port_speed,$port_duplex,'',$port_mac,$port_mtu));
}
echo $tbl->getTable();
}
else
{
echo $options['list'];
echo("Usage of console-ui.php:
if ($options['l'] == 'eventlog') {
$tbl = new Console_Table();
$tbl->setHeaders(array('Date time', 'Host', 'Message', 'Type', 'Reference'));
if (is_numeric($options['d'])) {
$sql = "WHERE host='".$options['d']."'";
}
-l What log type we want to see:
$query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E $sql ORDER BY `datetime` DESC LIMIT 20";
foreach (dbFetchRows($query, $param) as $entry) {
$tbl->addRow(array($entry['datetime'], gethostbyid($entry['host']), $entry['message'], $entry['type'], $entry['reference']));
}
echo $tbl->getTable();
}
else if ($options['l'] == 'syslog') {
$tbl = new Console_Table();
$tbl->setHeaders(array('Date time', 'Host', 'Program', 'Message', 'Level', 'Facility'));
if (is_numeric($options['d'])) {
$sql = "WHERE device_id='".$options['d']."'";
}
$query = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog AS S $sql_query ORDER BY `timestamp` DESC LIMIT 20";
foreach (dbFetchRows($query, $param) as $entry) {
$tbl->addRow(array($entry['timestamp'], gethostbyid($entry['device_id']), $entry['program'], $entry['msg'], $entry['level'], $entry['facility']));
}
echo $tbl->getTable();
}
else if ($options['list'] == 'devices') {
$tbl = new Console_Table();
$tbl->setHeaders(array('Device ID', 'Device Hostname'));
$query = 'SELECT device_id,hostname FROM `devices` ORDER BY hostname';
foreach (dbFetchRows($query, $sql_param) as $device) {
$tbl->addRow(array($device['device_id'], $device['hostname']));
}
echo $tbl->getTable();
exit;
}
else if (isset($options['device-stats'])) {
$tbl = new Console_Table();
$tbl->setHeaders(array('Port name', 'Status', 'IPv4 Address', 'Speed In', 'Speed Out', 'Packets In', 'Packets Out', 'Speed', 'Duplex', 'Type', 'MAC Address', 'MTU'));
foreach (dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($options['d'])) as $port) {
if ($port['ifOperStatus'] == 'up') {
$port['in_rate'] = ($port['ifInOctets_rate'] * 8);
$port['out_rate'] = ($port['ifOutOctets_rate'] * 8);
$in_perc = @round(($port['in_rate'] / $port['ifSpeed'] * 100));
$out_perc = @round(($port['in_rate'] / $port['ifSpeed'] * 100));
}
if ($port['ifSpeed']) {
$port_speed = humanspeed($port['ifSpeed']);
}
if ($port[ifDuplex] != 'unknown') {
$port_duplex = $port['ifDuplex'];
}
if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != '') {
$port_mac = formatMac($port['ifPhysAddress']);
}
if ($port['ifMtu'] && $port['ifMtu'] != '') {
$port_mtu = $port['ifMtu'];
}
$tbl->addRow(array($port['ifDescr'], $port['ifOperStatus'], '', formatRates($port['in_rate']), formatRates($port['out_rate']), format_bi($port['ifInUcastPkts_rate']).'pps', format_bi($port['ifOutUcastPkts_rate']).'pps', $port_speed, $port_duplex, '', $port_mac, $port_mtu));
}//end foreach
echo $tbl->getTable();
}
else {
echo $options['list'];
echo "Usage of console-ui.php:
-l What log type we want to see:
eventlog = Event log messages
syslog = Syslog messages
-d Specify the device id to filter results
-d Specify the device id to filter results
--list What to list
--list What to list
devices = list devices and device id's
--device-stats Lists the port statistics for a given device
--device-stats Lists the port statistics for a given device
Examples:
#1 php console-ui.php -l eventlog -d 1
#2 php console-ui.php --list=devices
Examples:
#1 php console-ui.php -l eventlog -d 1
#2 php console-ui.php --list=devices
");
exit;
}
echo(print $console_color->convert("%rLast update at ". date("Y-m-d h:i:s")."%n\n\n"));
sleep(5);
}
?>
";
exit;
}//end if
echo print $console_color->convert('%rLast update at '.date('Y-m-d h:i:s')."%n\n\n");
sleep(5);
}//end while

View File

@@ -1,82 +1,79 @@
#!/usr/bin/env php
<?php
///////////////////////////////////////////////////////////////////////////////////////
///
// A small script to grab the NTP Client statistics from a NTPD server
// Needed commands: php, ntpd, ntpq
///
// Install:
// Add the following to your snmpd.conf file:
// extend ntpclient /opt/librenms/scripts/ntp-client.php
///
// Version 1.1 By:
// All In One - Dennis de Houx <info@all-in-one.be>
///
///////////////////////////////////////////////////////////////////////////////////////
// A small script to grab the NTP Client statistics from a NTPD server
// Needed commands: php, ntpd, ntpq
//
// Install:
// Add the following to your snmpd.conf file:
// extend ntpclient /opt/librenms/scripts/ntp-client.php
//
// Version 1.1 By:
// All In One - Dennis de Houx <info@all-in-one.be>
//
// START SETTINGS ///
$ntpq = '/usr/sbin/ntpq';
// Change this to true if you have clk_jitter, sys_jitter in the ntpq -c rv output
$newstats_style = false;
// END SETTINGS ///
// DO NOT EDIT UNDER THIS LINE
$cmd = shell_exec($ntpq." -c rv | grep '^offset'");
if ($newstats_style) {
$cmd2 = shell_exec($ntpq." -c rv | grep '^clk_wander'");
}
else {
$cmd2 = shell_exec($ntpq." -c rv | grep '^stability'");
}
$vars = array();
$vars2 = array();
$vars = explode(',', $cmd);
$vars2 = explode(',', $cmd2);
// START SETTINGS ///
function doSNMPv2($vars, $vars2, $newstats_style)
{
$ntp = array();
foreach ($vars as $item => $value) {
if (!empty($value)) {
$temp = explode('=', $value);
if (isset($temp[1])) {
$ntp[trim($temp[0])] = trim($temp[1]);
}
}
}
$ntpq = "/usr/sbin/ntpq";
# Change this to true if you have clk_jitter, sys_jitter in the ntpq -c rv output
$newstats_style = false;
foreach ($vars2 as $item => $value) {
if (!empty($value)) {
$temp = explode('=', $value);
if (isset($temp[1])) {
$ntp[trim($temp[0])] = trim($temp[1]);
}
}
}
// END SETTINGS ///
$var = array();
$var['offset'] = (isset($ntp['offset']) ? $ntp['offset'] : 'U');
$var['frequency'] = (isset($ntp['frequency']) ? $ntp['frequency'] : 'U');
if ($newstats_style) {
$var['jitter'] = (isset($ntp['clk_jitter']) ? $ntp['clk_jitter'] : 'U');
$var['noise'] = (isset($ntp['sys_jitter']) ? $ntp['sys_jitter'] : 'U');
$var['stability'] = (isset($ntp['clk_wander']) ? $ntp['clk_wander'] : 'U');
}
else {
$var['jitter'] = (isset($ntp['jitter']) ? $ntp['jitter'] : 'U');
$var['noise'] = (isset($ntp['noise']) ? $ntp['noise'] : 'U');
$var['stability'] = (isset($ntp['stability']) ? $ntp['stability'] : 'U');
}
foreach ($var as $item => $count) {
echo $count."\n";
}
}//end doSNMPv2()
///
// DO NOT EDIT BENETH THIS LINE
///
///////////////////////////////////////////////////////////////////////////////////////
$cmd = shell_exec($ntpq." -c rv | grep '^offset'");
if ($newstats_style) {
$cmd2 = shell_exec($ntpq." -c rv | grep '^clk_wander'");
} else {
$cmd2 = shell_exec($ntpq." -c rv | grep '^stability'");
}
$vars = array();
$vars2 = array();
$vars = explode(',', $cmd);
$vars2 = explode(',', $cmd2);
function doSNMPv2($vars, $vars2, $newstats_style) {
$ntp = array();
foreach ($vars as $item=>$value) {
if (!empty($value)) {
$temp = explode('=', $value);
if (isset($temp[1])) {
$ntp[trim($temp[0])] = trim($temp[1]);
}
}
}
foreach ($vars2 as $item=>$value) {
if (!empty($value)) {
$temp = explode('=', $value);
if (isset($temp[1])) {
$ntp[trim($temp[0])] = trim($temp[1]);
}
}
}
$var = array();
$var['offset'] = (isset($ntp['offset']) ? $ntp['offset'] : "U");
$var['frequency'] = (isset($ntp['frequency']) ? $ntp['frequency'] : "U");
if ($newstats_style) {
$var['jitter'] = (isset($ntp['clk_jitter']) ? $ntp['clk_jitter'] : "U");
$var['noise'] = (isset($ntp['sys_jitter']) ? $ntp['sys_jitter'] : "U");
$var['stability'] = (isset($ntp['clk_wander']) ? $ntp['clk_wander'] : "U");
} else {
$var['jitter'] = (isset($ntp['jitter']) ? $ntp['jitter'] : "U");
$var['noise'] = (isset($ntp['noise']) ? $ntp['noise'] : "U");
$var['stability'] = (isset($ntp['stability']) ? $ntp['stability'] : "U");
}
foreach ($var as $item=>$count) {
echo $count."\n";
}
}
doSNMPv2($vars, $vars2, $newstats_style);
?>
doSNMPv2($vars, $vars2, $newstats_style);

View File

@@ -1,89 +1,83 @@
#!/usr/bin/env php
<?php
///////////////////////////////////////////////////////////////////////////////////////
///
// A small script to grab the NTPD Server statistics from a NTPD server
// Needed commands: php, ntpd, ntpq, ntpdc
///
// Install:
// Add the following to your snmpd.conf file:
// extend ntpdserver /opt/librenms/scripts/ntpd-server.php
///
// Version 1.1 By:
// All In One - Dennis de Houx <info@all-in-one.be>
///
///////////////////////////////////////////////////////////////////////////////////////
// A small script to grab the NTPD Server statistics from a NTPD server
// Needed commands: php, ntpd, ntpq, ntpdc
//
// Install:
// Add the following to your snmpd.conf file:
// extend ntpdserver /opt/librenms/scripts/ntpd-server.php
//
// Version 1.1 By:
// All In One - Dennis de Houx <info@all-in-one.be>
// START SETTINGS ///
$ntpq = '/usr/sbin/ntpq';
$ntpdc = '/usr/sbin/ntpdc';
// Change this to true if you have clk_jitter, sys_jitter in the ntpq -c rv output
$newstats_style = false;
// END SETTINGS ///
// DO NOT EDIT UNDER THIS LINE
$cmd = shell_exec($ntpq.' -c rv');
$cmd2 = shell_exec($ntpdc.' -c iostats');
$vars = array();
$vars2 = array();
$vars = explode(',', $cmd);
$vars2 = eregi_replace(' ', '', $cmd2);
$vars2 = explode("\n", $vars2);
// START SETTINGS ///
function doSNMPv2($vars, $vars2, $newstats_style)
{
$ntpd = array();
foreach ($vars as $item => $value) {
if (!empty($value)) {
$temp = explode('=', $value);
if (isset($temp[1])) {
$ntpd[trim($temp[0])] = trim($temp[1]);
}
}
}
$ntpq = "/usr/sbin/ntpq";
$ntpdc = "/usr/sbin/ntpdc";
# Change this to true if you have clk_jitter, sys_jitter in the ntpq -c rv output
$newstats_style = false;
foreach ($vars2 as $item => $value) {
if (!empty($value)) {
$temp = explode(':', $value);
if (isset($temp[1])) {
$ntpd[trim($temp[0])] = trim($temp[1]);
}
}
}
// END SETTINGS ///
$var = array();
$var['stratum'] = (isset($ntpd['stratum']) ? $ntpd['stratum'] : 'U');
$var['offset'] = (isset($ntpd['offset']) ? $ntpd['offset'] : 'U');
$var['frequency'] = (isset($ntpd['frequency']) ? $ntpd['frequency'] : 'U');
if ($newstats_style) {
$var['jitter'] = (isset($ntpd['clk_jitter']) ? $ntpd['clk_jitter'] : 'U');
$var['noise'] = (isset($ntpd['sys_jitter']) ? $ntpd['sys_jitter'] : 'U');
$var['stability'] = (isset($ntpd['clk_wander']) ? $ntpd['clk_wander'] : 'U');
}
else {
$var['jitter'] = (isset($ntpd['jitter']) ? $ntpd['jitter'] : 'U');
$var['noise'] = (isset($ntpd['noise']) ? $ntpd['noise'] : 'U');
$var['stability'] = (isset($ntpd['stability']) ? $ntpd['stability'] : 'U');
}
$var['uptime'] = (isset($ntpd['timesincereset']) ? $ntpd['timesincereset'] : 'U');
$var['buffer_recv'] = (isset($ntpd['receivebuffers']) ? $ntpd['receivebuffers'] : 'U');
$var['buffer_free'] = (isset($ntpd['freereceivebuffers']) ? $ntpd['freereceivebuffers'] : 'U');
$var['buffer_used'] = (isset($ntpd['usedreceivebuffers']) ? $ntpd['usedreceivebuffers'] : 'U');
$var['packets_drop'] = (isset($ntpd['droppedpackets']) ? $ntpd['droppedpackets'] : 'U');
$var['packets_ignore'] = (isset($ntpd['ignoredpackets']) ? $ntpd['ignoredpackets'] : 'U');
$var['packets_recv'] = (isset($ntpd['receivedpackets']) ? $ntpd['receivedpackets'] : 'U');
$var['packets_sent'] = (isset($ntpd['packetssent']) ? $ntpd['packetssent'] : 'U');
foreach ($var as $item => $count) {
echo $count."\n";
}
}//end doSNMPv2()
///
// DO NOT EDIT BENETH THIS LINE
///
///////////////////////////////////////////////////////////////////////////////////////
$cmd = shell_exec($ntpq." -c rv");
$cmd2 = shell_exec($ntpdc." -c iostats");
$vars = array();
$vars2 = array();
$vars = explode(',', $cmd);
$vars2 = eregi_replace(' ', '', $cmd2);
$vars2 = explode("\n", $vars2);
function doSNMPv2($vars, $vars2, $newstats_style) {
$ntpd = array();
foreach ($vars as $item=>$value) {
if (!empty($value)) {
$temp = explode('=', $value);
if (isset($temp[1])) {
$ntpd[trim($temp[0])] = trim($temp[1]);
}
}
}
foreach ($vars2 as $item=>$value) {
if (!empty($value)) {
$temp = explode(':', $value);
if (isset($temp[1])) {
$ntpd[trim($temp[0])] = trim($temp[1]);
}
}
}
$var = array();
$var['stratum'] = (isset($ntpd['stratum']) ? $ntpd['stratum'] : "U");
$var['offset'] = (isset($ntpd['offset']) ? $ntpd['offset'] : "U");
$var['frequency'] = (isset($ntpd['frequency']) ? $ntpd['frequency'] : "U");
if ($newstats_style) {
$var['jitter'] = (isset($ntpd['clk_jitter']) ? $ntpd['clk_jitter'] : "U");
$var['noise'] = (isset($ntpd['sys_jitter']) ? $ntpd['sys_jitter'] : "U");
$var['stability'] = (isset($ntpd['clk_wander']) ? $ntpd['clk_wander'] : "U");
} else {
$var['jitter'] = (isset($ntpd['jitter']) ? $ntpd['jitter'] : "U");
$var['noise'] = (isset($ntpd['noise']) ? $ntpd['noise'] : "U");
$var['stability'] = (isset($ntpd['stability']) ? $ntpd['stability'] : "U");
}
$var['uptime'] = (isset($ntpd['timesincereset']) ? $ntpd['timesincereset'] : "U");
$var['buffer_recv'] = (isset($ntpd['receivebuffers']) ? $ntpd['receivebuffers'] : "U");
$var['buffer_free'] = (isset($ntpd['freereceivebuffers']) ? $ntpd['freereceivebuffers'] : "U");
$var['buffer_used'] = (isset($ntpd['usedreceivebuffers']) ? $ntpd['usedreceivebuffers'] : "U");
$var['packets_drop'] = (isset($ntpd['droppedpackets']) ? $ntpd['droppedpackets'] : "U");
$var['packets_ignore'] = (isset($ntpd['ignoredpackets']) ? $ntpd['ignoredpackets'] : "U");
$var['packets_recv'] = (isset($ntpd['receivedpackets']) ? $ntpd['receivedpackets'] : "U");
$var['packets_sent'] = (isset($ntpd['packetssent']) ? $ntpd['packetssent'] : "U");
foreach ($var as $item=>$count) {
echo $count."\n";
}
}
doSNMPv2($vars, $vars2, $newstats_style);
?>
doSNMPv2($vars, $vars2, $newstats_style);

View File

@@ -1,84 +1,76 @@
#!/usr/bin/env php
<?php
///////////////////////////////////////////////////////////////////////////////////////
///
// A small script to grab the DNS statistics from a PowerDNS server
// Needed commands: php, pdns_control
///
// Install:
// Add the following to your snmpd.conf file:
// extend powerdns /opt/librenms/scripts/powerdns.php
///
// Version 1.0 By:
// All In One - Dennis de Houx <info@all-in-one.be>
///
///////////////////////////////////////////////////////////////////////////////////////
// A small script to grab the DNS statistics from a PowerDNS server
// Needed commands: php, pdns_control
//
// Install:
// Add the following to your snmpd.conf file:
// extend powerdns /opt/librenms/scripts/powerdns.php
//
// Version 1.0 By:
// All In One - Dennis de Houx <info@all-in-one.be>
// START SETTINGS ///
$pdnscontrol = "/usr/bin/pdns_control";
$pdnscontrol = '/usr/bin/pdns_control';
// END SETTINGS ///
// DO NOT EDIT UNDER THIS LINE
//
$cmd = shell_exec($pdnscontrol.' show \*');
$vars = array();
$vars = explode(',', $cmd);
///
// DO NOT EDIT BENETH THIS LINE
///
///////////////////////////////////////////////////////////////////////////////////////
$cmd = shell_exec($pdnscontrol." show \*");
$vars = array();
$vars = explode(',', $cmd);
function doSNMP($vars) {
foreach ($vars as $item=>$value) {
$value = trim($value);
if (!empty($value)) {
echo $value."\n";
}
}
}
function doSNMPv2($vars) {
$pdns = array();
foreach ($vars as $item=>$value) {
if (!empty($value)) {
$temp = explode('=', $value);
if (isset($temp[1])) {
$pdns[$temp[0]] = $temp[1];
}
}
}
$var = array();
$var['corrupt-packets'] = (isset($pdns['corrupt-packets']) ? $pdns['corrupt-packets'] : "U");
$var['deferred-cache-inserts'] = (isset($pdns['deferred-cache-inserts']) ? $pdns['deferred-cache-inserts'] : "U");
$var['deferred-cache-lookup'] = (isset($pdns['deferred-cache-lookup']) ? $pdns['deferred-cache-lookup'] : "U");
$var['latency'] = (isset($pdns['latency']) ? $pdns['latency'] : "U");
$var['packetcache-hit'] = (isset($pdns['packetcache-hit']) ? $pdns['packetcache-hit'] : "U");
$var['packetcache-miss'] = (isset($pdns['packetcache-miss']) ? $pdns['packetcache-miss'] : "U");
$var['packetcache-size'] = (isset($pdns['packetcache-size']) ? $pdns['packetcache-size'] : "U");
$var['qsize-q'] = (isset($pdns['qsize-q']) ? $pdns['qsize-q'] : "U");
$var['query-cache-hit'] = (isset($pdns['query-cache-hit']) ? $pdns['query-cache-hit'] : "U");
$var['query-cache-miss'] = (isset($pdns['query-cache-miss']) ? $pdns['query-cache-miss'] : "U");
$var['recursing-answers'] = (isset($pdns['recursing-answers']) ? $pdns['recursing-answers'] : "U");
$var['recursing-questions'] = (isset($pdns['recursing-questions']) ? $pdns['recursing-questions'] : "U");
$var['servfail-packets'] = (isset($pdns['servfail-packets']) ? $pdns['servfail-packets'] : "U");
$var['tcp-answers'] = (isset($pdns['tcp-answers']) ? $pdns['tcp-answers'] : "U");
$var['tcp-queries'] = (isset($pdns['tcp-queries']) ? $pdns['tcp-queries'] : "U");
$var['timedout-packets'] = (isset($pdns['timedout-packets']) ? $pdns['timedout-packets'] : "U");
$var['udp-answers'] = (isset($pdns['udp-answers']) ? $pdns['udp-answers'] : "U");
$var['udp-queries'] = (isset($pdns['udp-queries']) ? $pdns['udp-queries'] : "U");
$var['udp4-answers'] = (isset($pdns['udp4-answers']) ? $pdns['udp4-answers'] : "U");
$var['udp4-queries'] = (isset($pdns['udp4-queries']) ? $pdns['udp4-queries'] : "U");
$var['udp6-answers'] = (isset($pdns['udp6-answers']) ? $pdns['udp6-answers'] : "U");
$var['udp6-queries'] = (isset($pdns['udp6-queries']) ? $pdns['udp6-queries'] : "U");
foreach ($var as $item=>$count) {
echo $count."\n";
}
}
function doSNMP($vars) {
foreach ($vars as $item => $value) {
$value = trim($value);
if (!empty($value)) {
echo $value."\n";
}
}
doSNMPv2($vars);
}//end doSNMP()
?>
function doSNMPv2($vars) {
$pdns = array();
foreach ($vars as $item => $value) {
if (!empty($value)) {
$temp = explode('=', $value);
if (isset($temp[1])) {
$pdns[$temp[0]] = $temp[1];
}
}
}
$var = array();
$var['corrupt-packets'] = (isset($pdns['corrupt-packets']) ? $pdns['corrupt-packets'] : 'U');
$var['deferred-cache-inserts'] = (isset($pdns['deferred-cache-inserts']) ? $pdns['deferred-cache-inserts'] : 'U');
$var['deferred-cache-lookup'] = (isset($pdns['deferred-cache-lookup']) ? $pdns['deferred-cache-lookup'] : 'U');
$var['latency'] = (isset($pdns['latency']) ? $pdns['latency'] : 'U');
$var['packetcache-hit'] = (isset($pdns['packetcache-hit']) ? $pdns['packetcache-hit'] : 'U');
$var['packetcache-miss'] = (isset($pdns['packetcache-miss']) ? $pdns['packetcache-miss'] : 'U');
$var['packetcache-size'] = (isset($pdns['packetcache-size']) ? $pdns['packetcache-size'] : 'U');
$var['qsize-q'] = (isset($pdns['qsize-q']) ? $pdns['qsize-q'] : 'U');
$var['query-cache-hit'] = (isset($pdns['query-cache-hit']) ? $pdns['query-cache-hit'] : 'U');
$var['query-cache-miss'] = (isset($pdns['query-cache-miss']) ? $pdns['query-cache-miss'] : 'U');
$var['recursing-answers'] = (isset($pdns['recursing-answers']) ? $pdns['recursing-answers'] : 'U');
$var['recursing-questions'] = (isset($pdns['recursing-questions']) ? $pdns['recursing-questions'] : 'U');
$var['servfail-packets'] = (isset($pdns['servfail-packets']) ? $pdns['servfail-packets'] : 'U');
$var['tcp-answers'] = (isset($pdns['tcp-answers']) ? $pdns['tcp-answers'] : 'U');
$var['tcp-queries'] = (isset($pdns['tcp-queries']) ? $pdns['tcp-queries'] : 'U');
$var['timedout-packets'] = (isset($pdns['timedout-packets']) ? $pdns['timedout-packets'] : 'U');
$var['udp-answers'] = (isset($pdns['udp-answers']) ? $pdns['udp-answers'] : 'U');
$var['udp-queries'] = (isset($pdns['udp-queries']) ? $pdns['udp-queries'] : 'U');
$var['udp4-answers'] = (isset($pdns['udp4-answers']) ? $pdns['udp4-answers'] : 'U');
$var['udp4-queries'] = (isset($pdns['udp4-queries']) ? $pdns['udp4-queries'] : 'U');
$var['udp6-answers'] = (isset($pdns['udp6-answers']) ? $pdns['udp6-answers'] : 'U');
$var['udp6-queries'] = (isset($pdns['udp6-queries']) ? $pdns['udp6-queries'] : 'U');
foreach ($var as $item => $count) {
echo $count."\n";
}
}//end doSNMPv2()
doSNMPv2($vars);

View File

@@ -3,28 +3,21 @@
// MYSQL Check - FIXME
// 1 UPDATE
require 'config.php';
require 'includes/functions.php';
include("config.php");
include("includes/functions.php");
if ($fd = @fopen($argv[1], 'r')) {
$data = fread($fd, 4096);
while (!feof($fd)) {
$data .= fread($fd, 4096);
}
if ($fd = @fopen($argv[1],'r'))
{
$data = fread($fd,4096);
while (!feof($fd))
{
$data .= fread($fd,4096);
}
foreach (explode("\n", $data) as $line)
{
$update = mysql_query($line);
// FIXME check query success?
echo("$line \n");
}
foreach (explode("\n", $data) as $line) {
$update = mysql_query($line);
// FIXME check query success?
echo "$line \n";
}
}
else
{
echo("ERROR: Could not open file \"$argv[1]\".\n");
else {
echo "ERROR: Could not open file \"$argv[1]\".\n";
}
?>