Modified add_graphs.php to add specific port and conditions

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
pshaw1
Posts: 3
Joined: Mon Apr 14, 2014 4:33 pm

Modified add_graphs.php to add specific port and conditions

Post by pshaw1 »

Hello,

I'm trying to add a little specific functionality to add_graphs.php to only add graphs of ports of specific description regex and snmp up. I modified the area of code that deals with selecting port indexes, as seen below.

Code: Select all

                $snmp_query_array = array();
		$snmp_query_array["snmp_query_id"]       = $dsGraph["snmpQueryId"];
		$snmp_query_array["snmp_index_on"]       = get_best_data_query_index_type($hostId, $dsGraph["snmpQueryId"]);
		$snmp_query_array["snmp_query_graph_id"] = $dsGraph["snmpQueryType"];

#		$snmp_indexes = db_fetch_assoc("SELECT snmp_index
#			FROM host_snmp_cache
#			WHERE host_id=" . $hostId . "
#			AND snmp_query_id=" . $dsGraph["snmpQueryId"] . "
#			AND field_name='" . $dsGraph["snmpField"] . "'
#			AND field_value='" . $dsGraph["snmpValue"] . "'");

		$snmp_indexes = array();
		# grab all indexes that are on the extra module cards
		$mylist = db_fetch_assoc("SELECT snmp_index FROM host_snmp_cache
			WHERE host_id=" . $hostId . "
			AND ( field_value like 'Ten%_/1/_' OR field_value like 'Gig%_/1/_')");
		# loop through each and regrab index is field_value is 'Up' and push onto array
		foreach ($mylist as $index) {
			$temp = db_fetch_assoc("SELECT snmp_index FROM host_snmp_cache
				WHERE host_id=" . $hostId . "
				AND snmp_index=" . $index["snmp_index"] . "
				AND field_value='Up'");
			# make sure temp is not empty
			if (!empty($temp)) {
				array_push($snmp_indexes, $temp[0]);
			}
		}
		if (sizeof($snmp_indexes)) {
			foreach ($snmp_indexes as $snmp_index) {
				#$snmp_query_array["snmp_index"] = $snmp_index["snmp_index"];
				$snmp_query_array["snmp_index"] = $snmp_index;
...as compared to the original section...

Code: Select all

		$snmp_query_array = array();
		$snmp_query_array["snmp_query_id"]       = $dsGraph["snmpQueryId"];
		$snmp_query_array["snmp_index_on"]       = get_best_data_query_index_type($hostId, $dsGraph["snmpQueryId"]);
		$snmp_query_array["snmp_query_graph_id"] = $dsGraph["snmpQueryType"];

		$snmp_indexes = db_fetch_assoc("SELECT snmp_index
			FROM host_snmp_cache
			WHERE host_id=" . $hostId . "
			AND snmp_query_id=" . $dsGraph["snmpQueryId"] . "
			AND field_name='" . $dsGraph["snmpField"] . "'
			AND field_value='" . $dsGraph["snmpValue"] . "'");
		print_r($snmp_indexes);

		if (sizeof($snmp_indexes)) {
			foreach ($snmp_indexes as $snmp_index) {
				$snmp_query_array["snmp_index"] = $snmp_index["snmp_index"];
To be specific, I am first grabbing all the indexes that match in the database field_value of TenGigabitEthernet*/1/* and GigabitEthernet*/1/*. Then, I filter that list to only include those indexes that also have an ifOperStatus of Up. The index array is created just fine, but when the graphs are made, something goes wrong. The graph titles are templated to do |host_description| - Traffic - |query_ifName|, but the |query_ifName| doesn't show up. That also affects the data sources not following the similiar default templating scheme.

No other sections of code were changed.

These are the commands I used to test to create graphs with the modified code and the original.

Code: Select all

php -q modified_add_graphs.php --graph-type=ds --graph-template-id=2 --host-id=118 --snmp-query-id=10 --snmp-query-type-id=28 --snmp-field=ifOperStatus --snmp-value=Up

Code: Select all

php -q add_graphs.php --graph-type=ds --graph-template-id=2 --host-id=118 --snmp-query-id=10 --snmp-query-type-id=28 --snmp-field=ifOperStatus --snmp-value="Up"
Thank you in advance for help.
pshaw1
Posts: 3
Joined: Mon Apr 14, 2014 4:33 pm

Re: Modified add_graphs.php to add specific port and conditi

Post by pshaw1 »

Please close.

The autom8 plugin does exactly what I want to do.

Thank you.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests