-
Notifications
You must be signed in to change notification settings - Fork 336
/
cluster_discovery_runnner.py
executable file
·136 lines (110 loc) · 4.34 KB
/
cluster_discovery_runnner.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
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
131
132
133
134
135
136
#!/usr/bin/env python
# Copyright (C) 2009-2012:
# Camille, VACQUIE
# Romain, FORLOT, romain.forlot@sydel.fr
#
# This file is part of Shinken.
#
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Shinken is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################
#
# cluster_discovery_runner.py script simply try to get informations
# from HACMP mib and failback on Safekit mib. SNMP for both product
# need to be activated. For Safekit, add a proxy into snmpd conf to
# include its mib into the master agent netsnmp.
#
# For SNMPv3 we created a default user using the command :
# net-snmp-config --create-snmpv3-user -a "mypassword" myuser
# Here the user name is myuser and his password is mypassword
#
###############################################################
### modules import
import netsnmp
import optparse
import re
##########
# menu #
##########
parser = optparse.OptionParser('%prog [options] -H HOSTADRESS -C SNMPCOMMUNITYREAD -O ARG1 -V SNMPVERSION -l SNMPSECNAME -L SNMPSECLEVEL -p SNMPAUTHPROTO -x SNMPAUTHPASS')
# user name and password are defined in /var/lib/net-snmp/snmpd.conf
parser.add_option("-H", "--hostname", dest="hostname", help="Hostname to scan")
parser.add_option("-C", "--community", dest="community", help="Community to scan (default:public)")
parser.add_option("-O", "--os", dest="os", help="OS from scanned host")
parser.add_option("-V", "--version", dest="version", type=int, help="Version number for SNMP (1, 2 or 3; default:1)")
parser.add_option("-l", "--login", dest="snmpv3_user", help="User name for snmpv3(default:admin)")
parser.add_option("-L", "--level", dest="snmpv3_level", help="Security level for snmpv3(default:authNoPriv)")
parser.add_option("-p", "--authproto", dest="snmpv3_auth", help="Authentication protocol for snmpv3(default:MD5)")
parser.add_option("-x", "--authpass", dest="snmpv3_auth_pass", help="Authentication password for snmpv3(default:monpassword)")
opts, args = parser.parse_args()
hostname = opts.hostname
os = opts.os
clSolution_by_os = { 'aix' : 'hacmp',
'linux': 'safekit',
}
if not opts.hostname:
parser.error("Requires one host and its os to scan (option -H)")
if not opts.os:
parser.error("Requires the os host(option -O)")
if opts.community:
community = opts.community
else:
community = 'public'
if opts.version:
version = opts.version
else:
version = 1
if opts.snmpv3_user:
snmpv3_user = opts.snmpv3_user
else:
snmpv3_user = 'myuser'
if opts.snmpv3_level:
snmpv3_level = opts.snmpv3_level
else:
snmpv3_level = 'authNoPriv'
if opts.snmpv3_auth:
snmpv3_auth = opts.snmpv3_auth
else:
snmpv3_auth = 'MD5'
if opts.snmpv3_auth_pass:
snmpv3_auth_pass = opts.snmpv3_auth_pass
else:
snmpv3_auth_pass = 'mypassword'
oid_safekit_moduleName = ".1.3.6.1.4.1.107.175.10.1.1.2"
oid_hacmp_clusterName = ".1.3.6.1.4.1.2.3.1.2.1.5.1.2"
##############
# functions #
##############
### Search for files systems presents on the target
def get_cluster_discovery(oid):
name= netsnmp.Varbind(oid)
result = netsnmp.snmpwalk(name, Version=version, DestHost=hostname, Community=community, SecName=snmpv3_user, SecLevel=snmpv3_level, AuthProto=snmpv3_auth, AuthPass=snmpv3_auth_pass)
nameList = list(result)
return nameList
### converts the listed files systems writing and display them on the standard output
def get_cluster_discovery_output(list):
names = []
for elt in list:
names.append(elt)
print "%s::%s=%s"%(hostname, clSolution, ','.join(names))# display like in the nmap model
###############
# execution #
###############
scan = []
clSolution = clSolution_by_os[os]
scan = get_cluster_discovery(oid_hacmp_clusterName)
if not scan:
scan = get_cluster_discovery(oid_safekit_moduleName)
clSolution = 'safekit'
get_cluster_discovery_output(scan)