-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHost.py
executable file
·65 lines (43 loc) · 1.58 KB
/
Host.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
from termcolor import colored
class Host:
#def __init__(self, zapi,hostname,host_group_id,template_id):
def __init__(self, zapi,hostname,host_group_id):
self.__zapi = zapi
self.__hostname = hostname
self.__host_group_id = host_group_id
#self.__template_id = template_id
def setHost(self,hostip):
try:
self.__zapi.host.create(
host=self.__hostname,
interfaces=[{
"type":1, # - 1
"main": 1,
"useip":1,
"ip":hostip,
"dns":"",
"port":"161"
}],
groups=[{
"groupid":self.__host_group_id
}],
macros=[{
"macro":"{$SNMP_COMMUNITY}",
"value":"comunity"
}])
#templates=self.__template_id)
print(colored('\t\n Host: {} criado com sucesso .... [OK] '.format(self.__hostname),'green'))
except Exception as e:
print(colored("\t\nError: {}".format(e),'red'))
def getHostID(self):
try:
hostid = self.__zapi.host.get(filter={"host": self.__hostname})
return hostid[0]['hostid']
except Exception as e:
print("Error: {}".format(e))
def getHostNome(self):
try:
hostname = self.__zapi.host.get(filter={"host": self.__hostname})
return hostname[0]['host']
except Exception as e:
print("Error: {}".format(e))