-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (56 loc) · 2.08 KB
/
main.py
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
import myLib
# Let's enter all this necessary credentials
myOidTable = myLib.OidTable()
myOidTable.oid = "1.3.6.1.4.1.XXXXX.X.X.X.X"
myOidTable.snmp.ip = "192.168.XX.XXX"
myOidTable.snmp.community = "COMMUNITY_NAME"
# Finds the number of rows in this table
myOidTable.numRow = myOidTable.getNumRow()
# oidColumn are the column where the information is located
# Usage: oidColumn(Displayed name, column in the oidTable)
myOidTable.addColumn(myLib.OidColumn(displayedName = "IP", oidColumn = 1))
myOidTable.addColumn(myLib.OidColumn(displayedName = "TTL", oidColumn = 2))
myOidTable.addColumn(myLib.OidColumn(displayedName = "Name", oidColumn = 3))
# We can directly export the file like this
myOidTable.exportTableToCSV("ip.csv")
# Or keep the array for further analysis
# We can use getColumnsValue() or getRowsValue()
myTable = myOidTable.getColumnsValue()
# Let's create a list of Counter
myCounters = myLib.Counters()
# And add new counters.
# We need to indicate its name, which column to analyse and what to look for.
myCounters.addCounter(
myLib.Counter(
displayedName = "IP en 10.30",
predicate = myLib.Predicate(
columnIndex = myOidTable.getColumnIndex("IP"),
value = "10.30")
)
)
myCounters.addCounter(
myLib.Counter(
displayedName = "IP en 10.61",
predicate = myLib.Predicate(
columnIndex = myOidTable.getColumnIndex("IP"),
value = "10.61")
)
)
myCounters.addCounter(
myLib.Counter(
displayedName = "IP en 192.168.17",
predicate = myLib.Predicate(
columnIndex = myOidTable.getColumnIndex("IP"),
value = "192.168.17")
)
)
myCounters.addCounter(
myLib.Counter(
displayedName = "IP en 192.168.40",
predicate = myLib.Predicate(
columnIndex = myOidTable.getColumnIndex("IP"),
value = "192.168.40")
)
)
# Let's export this analysis in a CSV file
myCounters.exportCountersCountToCSV("stats.csv", myTable)