Module: check_mk
Branch: master
Commit: 036954520ffcb2c1fa3e6a56cf2a9c0ab3008c43
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=036954520ffcb2…
Author: Goetz Golla <gg(a)mathias-kettner.de>
Date: Mon Apr 13 10:34:30 2015 +0200
wato_import.py script can now also handle tags
---
doc/treasures/wato_import.py | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/doc/treasures/wato_import.py b/doc/treasures/wato_import.py
old mode 100755
new mode 100644
index 4502ddd..9534428
--- a/doc/treasures/wato_import.py
+++ b/doc/treasures/wato_import.py
@@ -32,19 +32,19 @@ try:
path = os.environ.pop('OMD_ROOT')
pathlokal = "~/etc/check_mk/conf.d/wato/"
pathlokal = os.path.expanduser(pathlokal)
- datei = open(sys.argv[1],'r')
+ datei = open(sys.argv[1],'r')
except:
print """Run this script inside a OMD site
Usage: ./wato_import.py csvfile.csv
CSV Example:
- wato_foldername;hostname;host_alias;ipaddress|None"""
+ wato_foldername;hostname|tags;host_alias;(ipaddress|None)"""
sys.exit()
folders = {}
for line in datei:
- if line.startswith('#'):
+ if line.startswith('#') or len(line.split(',')) < 4:
continue
- ordner, name, alias, ipaddress = line.split(';')[:4]
+ ordner, name, alias, ipaddress = line.split(',')[:4]
if ordner:
try:
os.makedirs(pathlokal+ordner)
@@ -53,24 +53,25 @@ for line in datei:
folders.setdefault(ordner,[])
ipaddress = ipaddress.strip()
if ipaddress == "None":
- ipaddress = False
+ ipaddress = False
folders[ordner].append((name,alias,ipaddress))
datei.close()
for folder in folders:
- all_hosts = ""
- host_attributes = ""
+ all_hosts = ""
+ host_attributes = ""
ips = ""
for name, alias, ipaddress in folders[folder]:
+ realname = name.split("|")[0]
all_hosts += "'%s',\n" % (name)
if ipaddress:
- host_attributes += "'%s' : {'alias' : u'%s',
'ipaddress' : '%s' },\n" % (name, alias, ipaddress)
- ips += "'%s' : '%s'," % ( name, ipaddress )
+ host_attributes += "'%s' : {'alias' : u'%s',
'ipaddress' : '%s' },\n" % (realname, alias, ipaddress)
+ ips += "'%s' : '%s'," % ( realname, ipaddress )
else:
- host_attributes += "'%s' : {'alias' : u'%s'
},\n" % (name, alias)
+ host_attributes += "'%s' : {'alias' : u'%s'
},\n" % (realname, alias)
- ziel = open(pathlokal + folder + '/hosts.mk','w')
+ ziel = open(pathlokal + folder + '/hosts.mk','w')
ziel.write('all_hosts += [')
ziel.write(all_hosts)
ziel.write(']\n\n')