File: set-syslog-ntp.py

package info (click to toggle)
snimpy 0.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 484 kB
  • ctags: 435
  • sloc: python: 3,361; makefile: 6
file content (71 lines) | stat: -rwxr-xr-x 2,215 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/snimpy

"""
Set NTP or syslog server on various switches

Usage:
 ./set-syslog-ntp.py [syslog|ntp] host community first [...]
"""

from __future__ import print_function

import os
import sys

load("SNMPv2-MIB")

host = sys.argv[2]
targets = sys.argv[4:]
operation = sys.argv[1]

try:
    s = M(host=host, community=sys.argv[3])
    sid = str(s.sysObjectID)
except snmp.SNMPException, e:
    print("%s: %s" % (host, e))
    sys.exit(1)

if sid.startswith("1.3.6.1.4.1.45.3."):
    # Nortel
    print("%s is Nortel 55xx" % host)
    load(os.path.expanduser("~/.snmp/mibs/SYNOPTICS-ROOT-MIB"))
    load(os.path.expanduser("~/.snmp/mibs/S5-ROOT-MIB"))
    if operation == "ntp":
        load(os.path.expanduser("~/.snmp/mibs/S5-AGENT-MIB"))
        s.s5AgSntpPrimaryServerAddress = targets[0]
        if len(targets) > 1:
            s.s5AgSntpSecondaryServerAddress = targets[1]
        else:
            s.s5AgSntpSecondaryServerAddress = "0.0.0.0"
        s.s5AgSntpState = "unicast"
        s.s5AgSntpManualSyncRequest = "requestSync"
    elif operation == "syslog":
        load(os.path.expanduser("~/.snmp/mibs/BN-LOG-MESSAGE-MIB"))
        s.bnLogMsgRemoteSyslogAddress = targets[0]
        s.bnLogMsgRemoteSyslogSaveTargets = "msgTypeInformational"
        s.bnLogMsgRemoteSyslogEnabled = True
elif sid.startswith("1.3.6.1.4.1.1872."):
    print("%s is Alteon" % host)
    load(os.path.expanduser("~/.snmp/mibs/ALTEON-ROOT-MIB"))
    if operation == "ntp":
        s.agNewCfgNTPServer = targets[0]
        if len(targets) > 1:
            s.agNewCfgNTPSecServer = targets[1]
        else:
            s.agNewCfgNTPSecServer = "0.0.0.0"
        s.agNewCfgNTPService = "enabled"
    elif operation == "syslog":
        s.agNewCfgSyslogHost = targets[0]
        s.agNewCfgSyslogFac = "local2"
        if len(targets) > 1:
            s.agNewCfgSyslog2Host = targets[1]
            s.agNewCfgSyslog2Fac = "local2"
        else:
            s.agNewCfgSyslog2Host = "0.0.0.0"
    if s.agApplyPending == "applyNeeded":
        if s.agApplyConfig == "complete":
            s.agApplyConfig = "idle"
        s.agApplyConfig = "apply"
else:
    print("%s is unknown (%s)" % (host, s.sysDescr))
    sys.exit(1)