Code

Added English translations for QUICKSTART.txt and obsess.README.
[nagixsc.git] / nagixsc_conf2xml.py
1 #!/usr/bin/python
2 #
3 # Nag(ix)SC -- nagixsc_conf2xml.py
4 #
5 # Copyright (C) 2009-2010 Sven Velt <sv@teamix.net>
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; only version 2 of the License is applicable.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20 import optparse
21 import sys
22 import urllib2
24 ##############################################################################
26 from nagixsc import *
28 ##############################################################################
30 parser = optparse.OptionParser()
32 parser.add_option('-c', '', dest='conffile', help='Config file')
33 parser.add_option('-o', '', dest='outfile', help='Output file name, "-" for STDOUT or HTTP POST URL')
34 parser.add_option('-e', '', dest='encoding', help='Encoding ("%s")' % '", "'.join(available_encodings()) )
35 parser.add_option('-H', '', dest='host', help='Hostname/section to search for in config file')
36 parser.add_option('-D', '', dest='service', help='Service description to search for in config file (needs -H)')
37 parser.add_option('-l', '', dest='httpuser', help='HTTP user name, if outfile is HTTP(S) URL')
38 parser.add_option('-a', '', dest='httppasswd', help='HTTP password, if outfile is HTTP(S) URL')
39 parser.add_option('-q', '', action='store_true', dest='quiet', help='Be quiet')
40 parser.add_option('-v', '', action='count', dest='verb', help='Verbose output')
42 parser.set_defaults(conffile='nagixsc.conf')
43 parser.set_defaults(outfile='-')
44 parser.set_defaults(encoding='base64')
45 parser.set_defaults(host=None)
46 parser.set_defaults(service=None)
47 parser.set_defaults(verb=0)
49 (options, args) = parser.parse_args()
51 ##############################################################################
53 if not check_encoding(options.encoding):
54         print 'Wrong encoding method "%s"!' % options.encoding
55         print 'Could be one of: "%s"' % '", "'.join(available_encodings())
56         sys.exit(127)
58 ##############################################################################
60 config = read_inifile(options.conffile)
62 if not config:
63         print 'Config file "%s" could not be read!' % options.conffile
64         sys.exit(5)
66 # Execute checks, build dict
67 checks = conf2dict(config, options.host, options.service)
69 # Convert to XML
70 xmldoc = xml_from_dict(checks, options.encoding)
72 # Output
73 response = write_xml_or_die(xmldoc, options.outfile, options.httpuser, options.httppasswd)
74 if response and not options.quiet:
75         print response