forked from zenoss/ZenPacks.zenoss.MySqlMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_device.py
71 lines (54 loc) · 1.6 KB
/
add_device.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
#!/usr/bin/env python
import random
import os
import string
import sys
import subprocess
def get_stuff():
# Zope magic ensues!
import Zope2
CONF_FILE = os.path.join(os.environ['ZENHOME'], 'etc', 'zope.conf')
# hide any positional arguments during Zope2 configure
_argv = sys.argv
sys.argv = [sys.argv[0], ] + [x for x in sys.argv[1:] if x.startswith("-")]
Zope2.configure(CONF_FILE)
sys.argv = _argv # restore normality
from Products.ZenModel.zendmd import _customStuff
return _customStuff()
def random_id(N):
return ''.join(
random.choice(string.ascii_uppercase + string.digits)
for x in range(N)
)
def add_device():
commit() # just in case of conflict error
dc = dmd.Devices.createOrganizer('/Server')
name = 'test_' + random_id(3)
device = dc.createInstance(name)
device.setPerformanceMonitor('localhost')
device.manageIp = '127.0.0.1'
device.setZenProperty('zMySQLConnectionString', 'root::3306;')
device.setZenProperty('zCollectorPlugins', ['MySQLCollector'])
device.index_object()
commit()
return name
def model_device(name):
os.system('zenmodeler run --device=%s' % name)
def python_monitor_device(name):
return subprocess.check_output(
['zenpython', 'run', '--device=' + name],
stderr=subprocess.STDOUT,
)
def delete_device(name):
commit() # WTF?
d = find(name)
d.deleteDevice()
commit()
stuff = get_stuff()
dmd = stuff['dmd']
commit = stuff['commit']
find = stuff['find']
if __name__ == '__main__':
name = add_device()
print name
model_device(name)