Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
... to conf2http (try "_livestatus" as config file name after putting path/ip&port into conf2http.cfg) ... new command live2xml and be a little bit more verbose in the config file of conf2http Signed-off-by: Sven Velt <sven@velt.de>
- Loading branch information
Showing
4 changed files
with
221 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/python | ||
|
||
import optparse | ||
import sys | ||
|
||
############################################################################## | ||
|
||
from nagixsc import * | ||
|
||
############################################################################## | ||
|
||
parser = optparse.OptionParser() | ||
|
||
parser.add_option('-s', '', dest='socket', help='Livestatus socket to connect') | ||
parser.add_option('-o', '', dest='outfile', help='Output file name, "-" for STDOUT or HTTP POST URL') | ||
parser.add_option('-e', '', dest='encoding', help='Encoding ("%s")' % '", "'.join(available_encodings()) ) | ||
parser.add_option('-H', '', dest='host', help='Hostname/section to search for in config file') | ||
parser.add_option('-D', '', dest='service', help='Service description to search for in config file (needs -H)') | ||
parser.add_option('-l', '', dest='httpuser', help='HTTP user name, if outfile is HTTP(S) URL') | ||
parser.add_option('-a', '', dest='httppasswd', help='HTTP password, if outfile is HTTP(S) URL') | ||
parser.add_option('-v', '', action='count', dest='verb', help='Verbose output') | ||
|
||
parser.set_defaults(socket=None) | ||
parser.set_defaults(outfile='-') | ||
parser.set_defaults(encoding='base64') | ||
parser.set_defaults(host=None) | ||
parser.set_defaults(service=None) | ||
parser.set_defaults(verb=0) | ||
|
||
(options, args) = parser.parse_args() | ||
|
||
############################################################################## | ||
|
||
if not options.socket: | ||
print 'No socket specified!\n' | ||
parser.print_help() | ||
sys.exit(1) | ||
|
||
if not check_encoding(options.encoding): | ||
print 'Wrong encoding method "%s"!' % options.encoding | ||
print 'Could be one of: "%s"' % '", "'.join(available_encodings()) | ||
sys.exit(1) | ||
|
||
############################################################################## | ||
|
||
# Prepare socket | ||
s_opts = prepare_socket(options.socket) | ||
|
||
# Read informations from livestatus | ||
checks = livestatus2dict(s_opts, options.host, options.service) | ||
|
||
# Convert to XML | ||
xmldoc = xml_from_dict(checks, options.encoding) | ||
|
||
# Output | ||
if options.outfile.startswith('http'): | ||
(headers, body) = encode_multipart(xmldoc, options.httpuser, options.httppasswd) | ||
|
||
try: | ||
response = urllib2.urlopen(urllib2.Request(options.outfile, body, headers)).read() | ||
except urllib2.HTTPError, error: | ||
print error | ||
sys.exit(6) | ||
except urllib2.URLError, error: | ||
print error.reason[1] | ||
sys.exit(7) | ||
|
||
print response | ||
|
||
elif options.outfile == '-': | ||
xmldoc.saveFormatFile('-', format=1) | ||
|
||
else: | ||
xmldoc.saveFile(options.outfile) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,55 @@ | ||
; Lines starting with "#" are defaults | ||
|
||
[server] | ||
; ### ip (0.0.0.0) ### | ||
; IP to bind server | ||
#ip: 0.0.0.0 | ||
|
||
; ### port (15666) ### | ||
; Port to bind server | ||
#port: 15666 | ||
|
||
; ### ssl (false) ### | ||
; Use SSL for server communication | ||
#ssl: false | ||
#sslcert: server.pem | ||
|
||
; ### sslcert (no default) ### | ||
; Read server key and certificate from this file | ||
; | ||
; Example | ||
;sslcert: server.pem | ||
|
||
; ### conf_dir (no default) ### | ||
; Directory where your config files are stored | ||
; | ||
; Absolute file names recommended, but for quick start it is set relative | ||
; to the source directory | ||
conf_dir: ./sample-configs/conf | ||
|
||
; ### pidfile (/var/run/nagixsc_conf2http.pid) ### | ||
; Where to store pid file if daemonizing | ||
; | ||
#pidfile: /var/run/nagixsc_conf2http.pid | ||
|
||
; ### livestatus_socket (no default) ### | ||
; Query mk-livestatus (http://mathias-kettner.de/checkmk_livestatus.html) | ||
; "livestatus_socket" could be | ||
; - local path and filename of socket ("/var/lib/nagios3/rw/live.sock") | ||
; - IPv4 address and port ("127.0.0.1:6557") | ||
; - IPv6 address and port ("[::1]:6557" or "::1:6557") | ||
; - DNS resolvable name and port ("localhost:6557") - could be IPv4 *or* IPv6! | ||
; | ||
; Examples: | ||
;livestatus_socket: /var/lib/nagios3/rw/live.sock | ||
;livestatus_socket: /usr/local/nagios/var/rw/live | ||
;livestatus_socket: 127.0.0.1:6557 | ||
;livestatus_socket: [::1]:6557 | ||
;livestatus_socket: localhost:6557 | ||
livestatus_socket: 172.21.254.99:6557 | ||
|
||
[users] | ||
; All users who are allowed to connect and request informations are stored here. | ||
; Passwords must be md5 encrypted, for example in shell use: | ||
; echo -n "Password" | md5sum - | ||
nagixsc: 019b0966d98fb71d1a4bc4ca0c81d5cc ; PW: nagixsc | ||
|