-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImport.py
executable file
·123 lines (69 loc) · 2.52 KB
/
Import.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
import csv
from Biblioteca import *
from ITService import ITservice
from Item import Item
from Interface import Interface
import pyprog
from time import sleep
class Import:
def __init__(self,zapi,file):
self.__zapi = zapi
self.__file = file
def ImportHost(self):
dataset = csv.reader(open(self.__file,'r'))
for data in dataset:
host = data[0]
ip = data[1]
group = data[2]
#template = data[3]
group_id = Group(self.__zapi,group)
#template_id = Template(self.__zapi,template)
#H = Host(self.__zapi,host,group_id.getGroupID(),template_id.getTemplate())
H = Host(self.__zapi,host,group_id.getGroupID())
H.setHost(ip)
def ImportSLA(self):
dataset = csv.reader(open(self.__file,'r'))
for data in dataset:
host = data[0]
group = data[1]
item = data[2]
its = ITservice(self.__zapi,host)
i = Item(self.__zapi,host)
its.setChild_itservices(group,i.getItem_triggerid(item))
def ImportDescriptionHost(self):
dataset = csv.reader(open(self.__file,'r'))
for data in dataset:
host = data[0]
description = data[1]
h = Host(self.__zapi,host,host_group_id=None,template_id=None)
upd = UpdateHost(self.__zapi,h.getHostID())
upd.updateDescription(description,host)
def ImportVisibleHostName(self):
dataset = csv.reader(open(self.__file,'r'))
for data in dataset:
vhost = data[0]
host = data[1]
h = Host(self.__zapi,host,host_group_id=None)
upd = UpdateHost(self.__zapi,h.getHostID())
upd.updateHostName(vhost,host)
def ImportNewInterface(self):
dataset = csv.reader(open(self.__file,'r'))
for data in dataset:
nip = data[1]
host = data[0]
h = Host(self.__zapi,host,host_group_id=None)
upd = Interface(self.__zapi,h.getHostID())
upd.setInterface(nip)
def contar_linhas_arquivo(self,file):
with open(self.__file, 'r') as f:
t = len(f.readlines())
f.close()
return (t)
def progresso(self,x):
prog = pyprog.ProgressBar("\tImportando Hosts ", "[OK]", x)
prog.update()
for i in range(x):
sleep(0.1)
prog.set_stat(i + 1)
prog.update()
prog.end()