this question was asked inside topic [http://forums.cacti.net/viewtopic.php?f ... s&start=15] about CatOS templates but so far I cant find solution.
We have Cacti 0.8.7g with many templates developed or downloaded from forums. For IOS Cacti is using this part for gathering IfAlias:
Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
Code: Select all
<ifAlias>
<name>Alias (IF-MIB)</name>
<method>walk</method>
<source>value</source>
<direction>input</direction>
<oid>.1.3.6.1.2.1.31.1.1.1.18</oid>
</ifAlias>
Code: Select all
cat /var/www/cacti/scripts/cisco_catos_interface.php
<?php
/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
die("<br><strong>This script is only meant to run at the command line.</strong>");
}
$no_http_headers = true;
include(dirname(__FILE__) . "/../include/global.php");
include(dirname(__FILE__) . "/../lib/snmp.php");
$oids = array(
"ifindex" => ".1.3.6.1.2.1.2.2.1.1",
"catosindex" => ".1.3.6.1.4.1.9.5.1.4.1.1.11",
"operstatus" => ".1.3.6.1.2.1.2.2.1.8",
"descr" => ".1.3.6.1.2.1.2.2.1.2",
"name" => ".1.3.6.1.2.1.31.1.1.1.1",
"type" => ".1.3.6.1.2.1.2.2.1.3",
"speed" => ".1.3.6.1.2.1.2.2.1.5",
"hwaddr" => ".1.3.6.1.2.1.2.2.1.6",
"inoctets" => ".1.3.6.1.2.1.2.2.1.10",
"outoctets" => ".1.3.6.1.2.1.2.2.1.16",
"hcinoctets" => ".1.3.6.1.2.1.31.1.1.1.6",
"hcoutoctets" => ".1.3.6.1.2.1.31.1.1.1.10",
"indiscards" => ".1.3.6.1.2.1.2.2.1.13",
"outdiscards" => ".1.3.6.1.2.1.2.2.1.19",
"innucastpkts" => ".1.3.6.1.2.1.2.2.1.12",
"outnucastpkts" => ".1.3.6.1.2.1.2.2.1.18",
"unicastpkts" => ".1.3.6.1.2.1.2.2.1.11",
"outucastpkts" => ".1.3.6.1.2.1.2.2.1.17",
"inerrors" => ".1.3.6.1.2.1.2.2.1.14",
"outerrors" => ".1.3.6.1.2.1.2.2.1.20",
"portname" => ".1.3.6.1.4.1.9.5.1.4.1.1.4",
"portduplex" => ".1.3.6.1.4.1.9.5.1.4.1.1.10",
"ifaddr" => ".1.3.6.1.2.1.4.20.1.1"
);
$hostname = $_SERVER["argv"][1];
$snmp_community = $_SERVER["argv"][2];
$snmp_version = $_SERVER["argv"][3];
$cmd = $_SERVER["argv"][4];
if ($cmd == "index") {
$arr_index = get_indexes($hostname, $snmp_community, $snmp_version, $oids["ifindex"]);
for ($i=0;($i<sizeof($arr_index));$i++) {
print $arr_index[$i] . "\n";
}
}
elseif ($cmd == "query") {
$arg = $_SERVER["argv"][5];
$arr_index = get_indexes($hostname, $snmp_community, $snmp_version, $oids["ifindex"]);
if ($arg == "index") {
for ($i=0;($i<sizeof($arr_index));$i++) {
print $arr_index[$i] . "!" . $arr_index[$i] . "\n";
}
}
elseif ($arg == "ifaddr") {
$arr = get_data_if($hostname, $snmp_community, $snmp_version, $oids["ifaddr"]);
for ($i=0;($i<sizeof($arr_index));$i++) {
print $arr_index[$i] . "!";
if (isset($arr[$i])) {
print $arr[$i] . "\n";
}
else {
print "\n";
}
}
}
elseif ($arg == "portname") {
$arr = get_data_catos($hostname, $snmp_community, $snmp_version, $arr_index, $oids["portname"], sizeof($arr_index));
for ($i=0;($i<sizeof($arr_index));$i++) {
print $arr_index[$i] . "!" . $arr[$i] . "\n";
}
}
elseif ($arg == "portduplex") {
$arr = get_data_catos($hostname, $snmp_community, $snmp_version,$arr_index, $oids["portduplex"], sizeof($arr_index));
for ($i=0;($i<sizeof($arr_index));$i++) {
print $arr_index[$i] . "!";
if ($arr[$i] == 1) {
print "half\n";
}
elseif ($arr[$i] == 2) {
print "full\n";
}
elseif ($arr[$i] == 3) {
print "disagree\n";
}
elseif ($arr[$i] == 4) {
print "auto\n";
}
else {
print "\n";
}
}
}
elseif ($arg == "speed"){
$arr = get_data_if($hostname, $snmp_community, $snmp_version, $oids["speed"]);
for ($i=0;($i<sizeof($arr_index));$i++) {
print $arr_index[$i] . "!";
if (floor($arr[$i]/(1000*1000*1000)) > 0) {
print round($arr[$i]/(1000*1000*1000),2) . " Gbps\n";
}
elseif (floor($arr[$i]/(1000*1000)) > 0) {
print round($arr[$i]/(1000*1000),2) . " Mbps\n";
}
elseif (floor($arr[$i]/(1000) > 0)) {
print round($arr[$i]/(1000),2) . " kbps\n";
}
else {
print "\n";
}
}
}
else {
$arr = get_data_if($hostname, $snmp_community, $snmp_version, $oids[$arg]);
for ($i=0;($i<sizeof($arr_index));$i++) {
print $arr_index[$i] . "!" . $arr[$i] . "\n";
}
}
}
elseif ($cmd == "get") {
$arg = $_SERVER["argv"][5];
$index = $_SERVER["argv"][6];
$arr_index = get_indexes($hostname, $snmp_community, $snmp_version, $oids["ifindex"]);
$arr = get_value_if($hostname, $snmp_community, $snmp_version, ($oids[$arg].".".$index));
print $arr;
}
function get_data_catos($hostname, $snmp_community, $snmp_version, $arr_if_index, $oid_data, $if_size) {
$oid_catos = ".1.3.6.1.4.1.9.5.1.4.1.1.11";
$arr_catos = cacti_snmp_walk($hostname, $snmp_community, $oid_catos, $snmp_version, "", "", "", "", "", "", "", 161, 1000);
for ($i=0;($i<sizeof($arr_catos));$i++) { /*in pivot steht nun an oid-ter stelle der index */
$arr_pivot[str_replace ($oid_catos, "", $arr_catos[$i]["oid"])] = ($arr_catos[$i]["value"])-1 ;
}
$arr = cacti_snmp_walk($hostname, $snmp_community, $oid_data, $snmp_version, "", "", "", "", "", "", "", 161, 1000);
for ($i=0;($i<sizeof($arr_if_index));$i++) {
$arr_retour2[$arr_pivot[str_replace ($oid_data, "", $arr[$i]["oid"])]] = $arr[$i]["value"];
}
for ($i=0;($i<sizeof($arr_if_index));$i++) {
if (isset($arr_retour2[$arr_if_index[$i]-1])) {
$arr_retour[$i] = $arr_retour2[$arr_if_index[$i]-1];
}
else {
$arr_retour[$i] = "";
}
}
return $arr_retour;
}
function get_data_if($hostname, $snmp_community, $snmp_version, $oid_data) {
$arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oid_data, $snmp_version, "", "", "", "", "", "", "", 161, 1000));
return $arr;
}
function get_value_if($hostname, $snmp_community, $snmp_version, $oid_data) {
$val = cacti_snmp_get ($hostname, $snmp_community, $oid_data, $snmp_version, "", "", "", "", "", "", "", 161, 1000);
return $val;
}
function get_indexes($hostname, $snmp_community, $snmp_version, $oid_data) {
$arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oid_data, $snmp_version, "", "", "", "", "", "", "", 161, 1000));
return $arr;
}
function reindex($arr) {
$return_arr = array();
for ($i=0;($i<sizeof($arr));$i++) {
$return_arr[$i] = $arr[$i]["value"];
}
return $return_arr;
}
?>
I started with adding OID to array but that is not enought so if anyone can get me a hand how to impement logic to this? Hints, examples or something I can start with?
Regards
Btw PF 2014