echo "ERROR: Unknown snmp-query-type-id (" . $dsGraph["snmpQueryType"] . ")\n"; echo "Try --snmp-query-id=" . $dsGraph["snmpQueryId"] . " --list-query-types\n"; exit(1); } } } /* Verify the host's existance */ if (!isset($hosts[$hostId]) || $hostId == 0) { echo "ERROR: Unknown Host ID ($hostId)\n"; echo "Try --list-hosts\n"; exit(1); } /* process the snmp fields */ $snmpFields = getSNMPFields($hostId); if ($listSNMPFields) { displaySNMPFields($snmpFields, $hostId, $quietMode); exit(0); } $snmpValues = array(); /* More sanity checking */ if (isset($dsGraph["snmpField"])) { if (!isset($snmpFields[$dsGraph["snmpField"]])) { echo "ERROR: Unknown snmp-field " . $dsGraph["snmpField"] . " for host $hostId\n"; echo "Try --list-snmp-fields\n"; exit(1); }
/* recache snmp data, this is time consuming, * but should happen only once even if multiple graphs * are added for the same data query * because we checked above, if dq was already associated */ run_data_query($hostId, $dsGraph["snmpQueryId"]); } } } /* Verify the host's existance */ if (!isset($hosts[$hostId]) || $hostId == 0) { echo "ERROR: Unknown Host ID ({$hostId})\n"; echo "Try --list-hosts\n"; exit(1); } /* process the snmp fields */ $snmpFields = getSNMPFields($hostId, $dsGraph["snmpQueryId"]); if ($listSNMPFields) { displaySNMPFields($snmpFields, $hostId, $quietMode); exit(0); } $snmpValues = array(); /* More sanity checking */ if ($dsGraph["snmpField"] != "") { if (!isset($snmpFields[$dsGraph["snmpField"]])) { echo "ERROR: Unknown snmp-field " . $dsGraph["snmpField"] . " for host {$hostId}\n"; echo "Try --list-snmp-fields\n"; exit(1); } $snmpValues = getSNMPValues($hostId, $dsGraph["snmpField"], $dsGraph["snmpQueryId"]); if ($dsGraph["snmpValue"] != "") { if (!isset($snmpValues[$dsGraph["snmpValue"]])) {
exit(0); } else { echo __("ERROR: You must supply a valid --device-id before you can list its SNMP fields") . "\n"; echo __("Try php -q device_list.php") . "\n"; exit(1); } } elseif ($listSNMPValues) { # list SNMP Values if (isset($device["id"]) && !($device["id"] === 0) && (db_fetch_cell("SELECT id FROM device WHERE id=" . $device["id"]))) { $snmpValues = array(); if ($ds_graph["snmpField"] != "") { /* snmp field(s) given: --list-snmp-values --device-id=[ID] --snmp-field=[Field] [--snmp-query-id=[ID]]*/ /* get fields for query id (if any) */ $snmpFields = getSNMPFields($device["id"], $ds_graph["snmpQueryId"]); if (!isset($snmpFields[$ds_graph["snmpField"]])) { echo __("ERROR: You must supply a valid --snmp-field (found: %s) before you can list its SNMP Values", $ds_graph["snmpField"]) . "\n"; echo __("Try --list-snmp-fields") . "\n"; exit(1); } /* get values for given field(s) and optional query id */ $snmpValues = getSNMPValues($device["id"], $ds_graph["snmpField"], $ds_graph["snmpQueryId"]); displaySNMPValues($snmpValues, $device["id"], $ds_graph["snmpField"], $quietMode); exit (0); } else { /* snmp fields not given */ if ($ds_graph["snmpQueryId"] == "") { /* snmp query id not given */ echo __("ERROR: You must supply a valid --snmp-field or --snmp-query-id before you can list its SNMP Values") . "\n"; echo __("Try --list-snmp-queries or --list-snmp-fields") . "\n"; exit (1);