We are currently using a php script to accomplish this. I've included the relevant script & XML. The data query populates the fields for creating the graph well for us under the cacti device. I had to write a follow up script to disable old data sources & create new graphs when we changed the breakers(IE: from 1 pole to 2 pole) because the snmp oid's change to reflect the breaker. That may not effect you but it might be something to keep in mind when getting everything setup. I hope this helps you.
Code: Select all
<?php
/* * ******************************************************************************
* Branch Circuit Monitoring
* Author: Jason Lantz
* Version 1.02
*
* Abstract: builds an array based on snmp values, allows values to be accessed using
* snmp commands
*
* Updated to php script server, -Rich.
*
* ****************************************************************************** */
date_default_timezone_set('America/Detroit');
$no_http_headers = true;
/* display No errors */
error_reporting(E_ERROR);
include_once(dirname(__FILE__) . "/../include/global.php");
include_once(dirname(__FILE__) . "/../lib/snmp.php");
if (!isset($called_by_script_server)) {
array_shift($_SERVER["argv"]);
print call_user_func_array("ss_eaton", $_SERVER['argv']);
}
function ss_eaton($hostname, $snmp_community, $cmd, $query_field, $query_index){
# define all OIDs we need for further processing
$oids = array(
"base" => "iso.3.6.1.4.1.534.6.6.4",
"topLevel" => ".1.3.6.1.4.1.534.6.6.4.1.3",
"pduNumPanels" => ".1.3.6.1.4.1.534.6.6.4.1.1.1.4.0",
"panelNumBreakers" => ".1.3.6.1.4.1.534.6.6.4.1.2.1.1.5",
"breakerNameTable" => ".1.3.6.1.4.1.534.6.6.4.1.3.1.1",
"breakerName" => ".1.3.6.1.4.1.534.6.6.4.1.3.1.1.2",
"breakerRating" => ".1.3.6.1.4.1.534.6.6.4.1.3.1.1.3",
"breakerNumPhases" => ".1.3.6.1.4.1.534.6.6.4.1.3.1.1.4",
"breakerMetersTable" => ".1.3.6.1.4.1.534.6.6.4.1.3.3",
"breakerPhaseCurrent" => ".1.3.6.1.4.1.534.6.6.4.1.3.3.1.5",
"breakerPhasePercentLoad" => ".1.3.6.1.4.1.534.6.6.4.1.3.3.1.6",
);
$snmp_version = 1; # snmp version
$snmp_port = 161; # snmp port
$snmp_timeout = 500; # snmp timeout
$snmp_retries = 3; # snmp retries
$max_oids = 1; # max oids for V2/V3 hosts
# required for SNMP V3
$snmp_auth_username = "";
$snmp_auth_password = "";
$snmp_auth_protocol = "";
$snmp_priv_passphrase = "";
$snmp_priv_protocol = "";
$snmp_context = "";
// define variables
$totalBreakers = 0;
$totalPhases = 0;
$xml_delimeter = '!';
/* * ***************************************************************************************
* snmp get command
* **************************************************************************************** */
if ($cmd == 'get') {
if ($query_field == 'Current')
$oid = $oids['breakerPhaseCurrent'] . "." . $query_index;
else
$oid = $oids['breakerPhasePercentLoad'] . "." . $query_index;
// get the number of panels and breakers per panel, poles per breaker
$return_arr = cacti_snmp_get($hostname, $snmp_community,
$oid, $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol,
$snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, SNMP_POLLER);
$return = $return_arr / 10.00;
print $return;
}
/* * *********************************************************************************************
* build the output array
* ********************************************************************************************** */
else {
$breakersPerPanel = cacti_snmp_walk($hostname, $snmp_community,
$oids["panelNumBreakers"], $snmp_version, $snmp_auth_username,
$snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol,
$snmp_context, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, SNMP_POLLER);
$phasesPerBreaker = cacti_snmp_walk($hostname, $snmp_community,
$oids["breakerNumPhases"], $snmp_version, $snmp_auth_username,
$snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol,
$snmp_context, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, SNMP_POLLER);
// determine the total number of breakers
for ($i = 0; $i < sizeof($breakersPerPanel); $i++) {
$totalBreakers += $breakersPerPanel[$i]['value'];
}
// determine the total number of phases
for ($i = 0; $i < sizeof($phasesPerBreaker); $i++) {
$totalPhases += $phasesPerBreaker[$i]['value'];
}
// walk the breakerNameTable for the breaker names, rating and number of phases
$breakerTable = cacti_snmp_walk($hostname, $snmp_community,
$oids["topLevel"], $snmp_version, $snmp_auth_username,
$snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol,
$snmp_context, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, SNMP_POLLER);
// parse out the information given from the snmp walk
for ($i = 0; $i < sizeof($breakerTable); $i++) {
if ($i < $totalBreakers) {
$breakerName[] = $breakerTable[$i]['value'];
} elseif ($i < ($totalBreakers * 2)) {
$breakerRating[] = $breakerTable[$i]['value'] / 10;
} elseif ($i < ($totalBreakers * 3)) {
$breakerNumPhases[] = $breakerTable[$i]['value'];
} elseif ($i < ($totalBreakers * 4)) {
$breakerTotalKWh[] = $breakerTable[$i]['value'];
} elseif ($i < ($totalBreakers * 5)) {
$breakerMonthlyKWh[] = $breakerTable[$i]['value'];
} elseif ($i < ($totalBreakers * 6)) {
$breakerYearlyKWh[] = $breakerTable[$i]['value'];
} else {
$breakerMetersTable[] = $breakerTable[$i];
}
}
// parse out the current and load, and build the index
for ($i = 0; $i < sizeof($breakerMetersTable); $i++) {
if ($i < $totalPhases) {
$breakerCurrent[] = $breakerMetersTable[$i]['value'] / 10.00;
$arr = explode('.', $breakerMetersTable[$i]['oid']);
$index[] = $arr[(sizeof($arr) - 3)] . "." . $arr[(sizeof($arr) - 2)] . "." . $arr[(sizeof($arr) - 1)];
} else {
$breakerLoad[] = $breakerMetersTable[$i]['value'];
}
}
// create the output array
$phaseIndex = $breakerNumPhases[0];
$nameIndex = 0;
foreach ($index as $key => $value) {
if ($phaseIndex == 0) {
$nameIndex++;
$phaseIndex = $breakerNumPhases[$nameIndex];
}
$outputTable[$value]['Index'] = $value;
$outputTable[$value]['Name'] = $breakerName[$nameIndex];
$outputTable[$value]['Rating'] = $breakerRating[$nameIndex];
$outputTable[$value]['Phases'] = $breakerNumPhases[$nameIndex];
$outputTable[$value]['Pole'] = substr($value, -1);
$outputTable[$value]['Current'] = $breakerCurrent[$key];
$outputTable[$value]['Load'] = $breakerLoad[$key];
$phaseIndex--;
}
/* * *************************************************************************
* snmp index
* ************************************************************************* */
if ($cmd == "index") {
for ($i = 0; $i < (sizeof($index)); $i++) {
print $index[$i] . "\n";
}
}
/* * ************************************************************************
* snmp query
* ************************************************************************ */
elseif ($cmd == 'query') {
for ($i = 0; $i < (sizeof($index)); $i++) {
print $index[$i] . $xml_delimeter . $outputTable[$index[$i]][$query_field] . "\n";
}
}
/* * **************************************************************************
* snmp total
* ************************************************************************** */
elseif ($cmd == 'total') {
return(sizeof($index));
} else {
return ("Invalid use of script query, required parameters:\n\n<hostname> <community> <cmd>\n");
}
}
}
?>