Complex Indexs and SNMP Data Queries

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
strandtc
Posts: 5
Joined: Fri Jun 25, 2010 6:51 pm

Complex Indexs and SNMP Data Queries

Post by strandtc »

I'm trying to build templates for an Eaton Branch Circuit Monitoring system. The idea is that this device monitors electrical load on multiple circuit breakers. Sometimes circuits use 1 wire (1 pole), sometimes 2 wires (2 pole), and sometimes 3 (3 pole).

I can create in index for the breakers themselves (note some gaps in the OID sequence):

Shown below is an example for the first 6 breakers.

Code: Select all

EATON-PDU-MIB::breakerName.1.1 = STRING: R7/TS1
EATON-PDU-MIB::breakerName.1.2 = STRING: R7/C1
EATON-PDU-MIB::breakerName.1.4 = STRING: R7/C2
EATON-PDU-MIB::breakerName.1.5 = STRING: R7/TS2
EATON-PDU-MIB::breakerName.1.6 = STRING: R7/C3
There is other information related to the breakers such as rating, number of phases, etc.

But what I want to graph is based on the breaker poles:

Code: Select all

EATON-PDU-MIB::breakerPhaseCurrent.1.1.1 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.1.2 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.2.1 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.4.2 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.5.1 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.5.3 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.6.3 = INTEGER: 0
So the index of breakers doesn't relate to the poles (phases). If I just create graphs based on the poles it doesn't give me a picture of the whole breaker.

Thoughts?

-Chris
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

You'll need to write a custom script (I'd suggest php script server) which will add up the number of breakerPhaseCurrent and report it back to cacti.
dionvdc
Posts: 46
Joined: Tue Feb 16, 2010 3:54 pm

Post by dionvdc »

strandtc wrote:
But what I want to graph is based on the breaker poles:

Code: Select all

EATON-PDU-MIB::breakerPhaseCurrent.1.1.1 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.1.2 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.2.1 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.4.2 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.5.1 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.5.3 = INTEGER: 0
EATON-PDU-MIB::breakerPhaseCurrent.1.6.3 = INTEGER: 0
So the index of breakers doesn't relate to the poles (phases). If I just create graphs based on the poles it doesn't give me a picture of the whole breaker.

Thoughts?
-Chris
If
breakerPhaseCurrent.1.1.1 refers to breaker 1 pole/phase 1
breakerPhaseCurrent.1.1.2 refers to breaker 1 pole/phase 2
...
breakerPhaseCurrent.1.6.3 refers to breaker 6 pole/phase 3
etc.

You could parse the index on the last two digits

Code: Select all

	<oid_index>.1.3.6.1.4.1.19746.1.6.3.1.1.1</oid_index>
	<oid_index_parse>OID/REGEXP:.*\.([0-9].[0-9]{1,2})$</oid_index_parse> 
	<index_order_type>numeric</index_order_type>
	<index_order>Index</index_order>
	<index_title_format>|chosen_order_field|</index_title_format>
	<fields>
		<Index>
			<name>Index</name>
			<method>walk</method>
			<source>index</source>
			<direction>input</direction>
I had to fiddle around with this to get it to work as i needed it.

Some info on parsing http://www.cacti.net/downloads/docs/htm ... y_xml.html
GreyFoxx
Posts: 3
Joined: Tue May 13, 2014 11:19 am

Re: Complex Indexs and SNMP Data Queries

Post by GreyFoxx »

I don't suppose you ever got this working did you? I'm looking to monitor the same kind of gear and working examples would be helpful :)
strandtc
Posts: 5
Joined: Fri Jun 25, 2010 6:51 pm

Re: Complex Indexs and SNMP Data Queries

Post by strandtc »

I have moved to a different team, but I believe we did in the end get Cacti to monitor the system. But I think we have a script outside of cacti that helps setup cacti to do the monitoring. I'll forward this to the guy who currently maintains the system.

-Chris
GreyFoxx
Posts: 3
Joined: Tue May 13, 2014 11:19 am

Re: Complex Indexs and SNMP Data Queries

Post by GreyFoxx »

strandtc wrote:I have moved to a different team, but I believe we did in the end get Cacti to monitor the system. But I think we have a script outside of cacti that helps setup cacti to do the monitoring. I'll forward this to the guy who currently maintains the system.

-Chris


That would be awesome! Thanks!
rlakomy
Posts: 1
Joined: Fri Apr 20, 2012 2:06 pm

Re: Complex Indexs and SNMP Data Queries

Post by rlakomy »

Howdy,

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.

~Rich

Code: Select all

<interface>
        <name>Eaton Xpert PDU</name>
        <script_path>|path_cacti|/scripts/ss_eaton.php</script_path>
        <script_function>ss_eaton</script_function>
        <arg_prepend>|host_hostname| |host_snmp_community|</arg_prepend>
        <script_server>php</script_server>
        <arg_index>index</arg_index>
        <arg_query>query</arg_query>
        <arg_get>get</arg_get>
        <arg_num_indexes>total</arg_num_indexes>
        <output_delimeter>!</output_delimeter>
        <index_order>Index</index_order>
        <fields>
                <Index>
                        <name>Index</name>
                        <direction>input</direction>
                        <query_name>Index</query_name>
                        
                </Index>
                <Name>
                        <name>Breaker Name</name>
                        <direction>input</direction>
                        <query_name>Name</query_name>
                </Name>
                <Rating>
                        <name>Rating</name>
                        <direction>input</direction>
                        <query_name>Rating</query_name>
                </Rating>
                <Phases>
                        <name>Phases</name>
                        <direction>input</direction>
                        <query_name>Phases</query_name>
                </Phases>
                <Pole>
                        <name>Pole</name>
                        <direction>input</direction>
                        <query_name>Pole</query_name>
                </Pole>
                <Current>
                        <name>Breaker Current</name>
                        <direction>output</direction>
                        <query_name>Current</query_name>
                </Current>
                <Load>
                        <name>Percent Load</name>
                        <direction>output</direction>
                        <query_name>Load</query_name>
                </Load>
        </fields>
</interface>

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");
    }
}
}
?>
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests