Code

Added English translations for QUICKSTART.txt and obsess.README.
[nagixsc.git] / nagixsc_live2xml.py
1 #!/usr/bin/python
2 #
3 # Nag(ix)SC -- nagixsc_live2xml.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
23 ##############################################################################
25 from nagixsc import *
27 ##############################################################################
29 parser = optparse.OptionParser()
31 parser.add_option('-s', '', dest='socket', help='Livestatus socket to connect')
32 parser.add_option('-o', '', dest='outfile', help='Output file name, "-" for STDOUT or HTTP POST URL')
33 parser.add_option('-e', '', dest='encoding', help='Encoding ("%s")' % '", "'.join(available_encodings()) )
34 parser.add_option('-H', '', dest='host', help='Hostname/section to search for in config file')
35 parser.add_option('-D', '', dest='service', help='Service description to search for in config file (needs -H)')
36 parser.add_option('-l', '', dest='httpuser', help='HTTP user name, if outfile is HTTP(S) URL')
37 parser.add_option('-a', '', dest='httppasswd', help='HTTP password, if outfile is HTTP(S) URL')
38 parser.add_option('-q', '', action='store_true', dest='quiet', help='Be quiet')
39 parser.add_option('-v', '', action='count', dest='verb', help='Verbose output')
41 parser.set_defaults(socket=None)
42 parser.set_defaults(outfile='-')
43 parser.set_defaults(encoding='base64')
44 parser.set_defaults(host=None)
45 parser.set_defaults(service=None)
46 parser.set_defaults(verb=0)
48 (options, args) = parser.parse_args()
50 ##############################################################################
52 if not options.socket:
53         print 'No socket specified!\n'
54         parser.print_help()
55         sys.exit(1)
57 if not check_encoding(options.encoding):
58         print 'Wrong encoding method "%s"!' % options.encoding
59         print 'Could be one of: "%s"' % '", "'.join(available_encodings())
60         sys.exit(1)
62 ##############################################################################
64 # Prepare socket
65 s_opts = prepare_socket(options.socket)
67 # Read informations from livestatus
68 checks = livestatus2dict(s_opts, options.host, options.service)
70 # Convert to XML
71 xmldoc = xml_from_dict(checks, options.encoding)
73 # Output
74 response = write_xml_or_die(xmldoc, options.outfile, options.httpuser, options.httppasswd)
75 if response and not options.quiet:
76         print response