Code

Changed license to GPL-2+ (from GPL-2only).
[nagixsc.git] / nagixsc_write_xml.py
1 #!/usr/bin/python
2 #
3 # Nag(ix)SC -- nagixsc_write_xml.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; either version 2 of the License, or (at your
10 # option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21 import nagixsc
22 import optparse
24 parser = optparse.OptionParser()
26 parser.add_option('-o', '', dest='outfile', help='(Path and) file name of status file, default STDOUT')
27 parser.add_option('-v', '', action='count', dest='verb', help='Verbose output')
29 parser.set_defaults(outfile='-')
30 parser.set_defaults(verb=0)
32 (options, args) = parser.parse_args()
34 checks = [{'host_name': 'host1',
35   'output': 'Nag(ix)SC: Check result is 24535725(>14400) seconds old  - DISK CRITICAL - free space: /home 775 MB (1% inode=91%);| /home=67584MB;61523;64941;0;68359',
36   'returncode': '2',
37   'service_description': 'Disk_Home',
38   'timestamp': 1234443420},
39  {'host_name': 'host1',
40   'output': 'Nag(ix)SC: Check result is 24535725(>14400) seconds old  - OK - load average: 0.00, 0.00, 0.00|load1=0.000;5.000;10.000;0; load5=0.000;5.000;10.000;0; load15=0.000;5.000;10.000;0;',
41   'returncode': '0',
42   'service_description': 'Load',
43   'timestamp': 1234443420},
44  {'host_name': 'host2',
45   'output': 'Nag(ix)SC: Check result is 24535735(>14400) seconds old  - PROCS OK: 163 processes',
46   'returncode': '0',
47   'service_description': 'Procs_Total',
48   'timestamp': 1234443410},
49  {'host_name': 'host2',
50   'output': 'Nag(ix)SC: Check result is 24535715(>14400) seconds old  - SWAP OK - 79% free (1492 MB out of 1906 MB) |swap=1492MB;953;476;0;1906',
51   'returncode': '0',
52   'service_description': 'Swap', },
53  {'host_name': 'host1',
54   'output': 'Nag(ix)SC: Check result is 24535725(>14400) seconds old  - DISK OK - free space: / 2167 MB (22% inode=97%);| /=7353MB;8568;9044;0;9520',
55   'returncode': '0',
56   'service_description': 'Disk_Root',
57   'timestamp': 1234443420},
58  {'host_name': 'host2',
59   'output': 'Nag(ix)SC: Check result is 24535735(>14400) seconds old  - USERS WARNING - 11 users currently logged in |users=11;10;15;0\n3 root sessions\n8 non-root sessions',
60   'returncode': '1',
61   'service_description': 'Users',
62   'timestamp': 1234443410}]
64 xmldoc = nagixsc.xml_from_dict(checks)
65 xmldoc.saveFile(options.outfile)