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;
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"];
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"