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; 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 nagixsc
21 import optparse
23 parser = optparse.OptionParser()
25 parser.add_option('-o', '', dest='outfile', help='(Path and) file name of status file, default STDOUT')
26 parser.add_option('-v', '', action='count', dest='verb', help='Verbose output')
28 parser.set_defaults(outfile='-')
29 parser.set_defaults(verb=0)
31 (options, args) = parser.parse_args()
33 checks = [{'host_name': 'host1',
34 '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',
35 'returncode': '2',
36 'service_description': 'Disk_Home',
37 'timestamp': 1234443420},
38 {'host_name': 'host1',
39 '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;',
40 'returncode': '0',
41 'service_description': 'Load',
42 'timestamp': 1234443420},
43 {'host_name': 'host2',
44 'output': 'Nag(ix)SC: Check result is 24535735(>14400) seconds old - PROCS OK: 163 processes',
45 'returncode': '0',
46 'service_description': 'Procs_Total',
47 'timestamp': 1234443410},
48 {'host_name': 'host2',
49 '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',
50 'returncode': '0',
51 'service_description': 'Swap', },
52 {'host_name': 'host1',
53 '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',
54 'returncode': '0',
55 'service_description': 'Disk_Root',
56 'timestamp': 1234443420},
57 {'host_name': 'host2',
58 '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',
59 'returncode': '1',
60 'service_description': 'Users',
61 'timestamp': 1234443410}]
63 xmldoc = nagixsc.xml_from_dict(checks)
64 xmldoc.saveFile(options.outfile)