$snmpValues = getSNMPValues($hostId, $dsGraph["snmpField"]); if (isset($dsGraph["snmpValue"])) { if (!isset($snmpValues[$dsGraph["snmpValue"]])) { echo "Unknown snmp-value for field " . $dsGraph["snmpField"] . " - " . $dsGraph["snmpValue"] . "\n"; echo "Try --snmp-field " . $dsGraph["snmpField"] . " --list-snmp-values\n"; return 1; } } } if ($listSNMPValues == 1) { if (!isset($dsGraph["snmpField"])) { echo "You must supply an snmp-field before you can list its values\n"; echo "Try --list-snmp-fields\n"; return 1; } displaySNMPValues($snmpValues, $hostId, $dsGraph["snmpField"]); return 0; } if (!isset($graphTemplates[$templateId])) { echo "Unknown graph-template-id (" . $templateId . ")\n"; echo "Try --list-graph-templates\n"; return 1; } if (!isset($templateId) || !isset($hostId)) { echo "Must have at least a host-id and a graph-template-id\n\n"; display_help(); return 1; } $returnArray = array(); if ($graph_type == "cg") { $empty = array();
$snmpValues = getSNMPValues($hostId, $dsGraph["snmpField"], $dsGraph["snmpQueryId"]); if ($dsGraph["snmpValue"] != "") { if (!isset($snmpValues[$dsGraph["snmpValue"]])) { echo "ERROR: Unknown snmp-value for field " . $dsGraph["snmpField"] . " - " . $dsGraph["snmpValue"] . "\n"; echo "Try --snmp-field=" . $dsGraph["snmpField"] . " --list-snmp-values\n"; exit(1); } } } if ($listSNMPValues) { if ($dsGraph["snmpField"] == "") { echo "ERROR: You must supply an snmp-field before you can list its values\n"; echo "Try --list-snmp-fields\n"; exit(1); } displaySNMPValues($snmpValues, $hostId, $dsGraph["snmpField"], $quietMode); exit(0); } if (!isset($graphTemplates[$templateId])) { echo "ERROR: Unknown graph-template-id (" . $templateId . ")\n"; echo "Try --list-graph-templates\n"; exit(1); } if (!isset($templateId) || !isset($hostId)) { echo "ERROR: Must have at least a host-id and a graph-template-id\n\n"; display_help(); exit(1); } if (strlen($cgInputFields)) { $fields = explode(" ", $cgInputFields); if ($templateId > 0) {
} 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); } else { /* snmp query id given, no snmp field(s), optional snmp field spec */ $rc = displaySNMPValuesExtended($device["id"], $ds_graph["snmpFieldSpec"], $ds_graph["snmpQueryId"], $quietMode); exit ($rc); } } } else { echo __("ERROR: You must supply a valid --device-id before you can list its SNMP values") . "\n";