-
Notifications
You must be signed in to change notification settings - Fork 0
/
classmap-policy-discover.php
executable file
·131 lines (94 loc) · 3.24 KB
/
classmap-policy-discover.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/php
<?php
/**
* SNMP discovery script for Zabbix providing multiple SNMP values combined by index
*
* @author Robin Roevens <robin.roevens (at) gmail.com>
*/
$snmpwalk = '/usr/bin/snmpwalk';
$argv[0] = basename($argv[0]);
$usage = <<<EOM
./classmap-policy-discover.php IPADDRESS "-v2c -c COMMUNITY"
IPADDRESS is the adress of the cisco device
"-v2c -c COMMUNITY" are snmpwalk parameters
will discover definded class policies
(e.g.
.1.3.6.1.4.1.9.9.166.1.7.1.1.1.1593 "name1"
.1.3.6.1.4.1.9.9.166.1.7.1.1.1.3463889 "name2"
.1.3.6.1.4.1.9.9.166.1.7.1.1.1.15715633 "data1"
)
and return SNMP OID suffixes for the QoS counter, according QoS enabled interface and policy name ..
(e.g.
#IFNAME_QOS}":"GigabitEthernet0\/0.8","
#QOSCN_OIDSUFFIX}":"45.38766593","
#QOS_POLICY}":"name2"},
#IFNAME_QOS}":"GigabitEthernet0\/0.4","
#QOSCN_OIDSUFFIX}":"41.46766573","
#QOS_POLICY}":"data1"},
)
EOM;
array_shift($argv);
// Check input
if (!is_array($argv) || !array_key_exists(0, $argv)) {
die($usage);
}
$host = $argv[0];
array_shift($argv);
if (!array_key_exists(0, $argv)) {
die($usage);
}
$snmpArgs = $argv[0];
array_shift($argv);
$oid_intnames = '.1.3.6.1.2.1.2.2.1.2';
$oid_qosint = '.1.3.6.1.4.1.9.9.166.1.1.1.1.4' ;
$oid_classname = '.1.3.6.1.4.1.9.9.166.1.7.1.1.1' ;
$oid_qosconfigindex = '.1.3.6.1.4.1.9.9.166.1.5.1.1.2'; //has to append qos intrface index and will get table with counter index per policy
// Get values
$intnames = shell_exec("$snmpwalk $snmpArgs -On -Oq $host $oid_intnames");
if (preg_match_all('/\.(\d+) "?([^"\r\n]*)/', $intnames, $matches_int)) {
}
$qosint = shell_exec("$snmpwalk $snmpArgs -On -Oq $host $oid_qosint");
if (preg_match_all('/\.(\d+) "?([^"\r\n]*)/', $qosint, $matches_qosint)) {
}
$cmname = shell_exec("$snmpwalk $snmpArgs -On -Oq $host $oid_classname");
if (preg_match_all('/\.(\d+) "?([^"\r\n]*)/', $cmname, $matches_cmname)) {
}
$qosinterface_index = Array ();
$qosinterface_name = Array ();
$qosinterface_policy_index = Array ();
$qosinterface_policy_string = Array ();
foreach ($matches_qosint[1] as $key => $value) {
$fkey = array_search ($matches_qosint[2][$key], $matches_int[1]);
$qosinterface_index[] = $value;
$qosinterface_name[] = $matches_int[2][$fkey];
}
foreach ($matches_cmname[1] as $pind => $pstr) {
$i = 0;
$policy_snmp_id = $pstr;
$policy = $matches_cmname[2][$pind];
foreach ($qosinterface_index as $value) {
$tempor = shell_exec("$snmpwalk $snmpArgs -On -Oq $host $oid_qosconfigindex.$value");
if (preg_match_all('/\.(\d+) "?([^"\r\n]*)/', $tempor, $matches_tempor)) {
}
$qosinterface_policy_index[$i][] = $matches_tempor[1][array_search ($policy_snmp_id,$matches_tempor[2])];
$qosinterface_policy_string[$i][] = $policy;
$i++;
}
}
// Build data array
$data = array('data' => array());
$i = 0;
$qi = 0;
foreach ($qosinterface_index as $key => $value) {
$pi = 0;
foreach ($qosinterface_policy_index[$qi] as $qkey){
$data['data'][$i]['{#IFNAME_QOS}'] = $qosinterface_name[$key];
$data['data'][$i]['{#QOSCN_OIDSUFFIX}'] = $value . "." . $qosinterface_policy_index[$qi][$pi];
$data['data'][$i]['{#QOS_POLICY}'] = $qosinterface_policy_string[$qi][$pi];
$i++;
$pi++;
}
$qi++;
}
// Spit it out as JSON
print json_encode($data);