File: get_service.py

package info (click to toggle)
pynag 0.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,196 kB
  • ctags: 1,181
  • sloc: python: 9,155; makefile: 200; sh: 151
file content (27 lines) | stat: -rwxr-xr-x 619 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python
import sys

if len(sys.argv) != 3:
    sys.stderr.write("Usage:  %s 'Service Description' 'Host Name'\n" % (sys.argv[0]))
    sys.exit(2)

## This is for the custom nagios module
sys.path.insert(1, '../')
from pynag.Parsers import config

service_description = sys.argv[1]
target_host = sys.argv[2]

## Create the plugin option
nc = config('/etc/nagios/nagios.cfg')
#nc.parse()
nc.parse()

service = nc.get_service(target_host, service_description)

if not service:
    sys.stderr.write("Service not found: %s %s\n" % (service_description, target_host))
    sys.exit(2)

print nc.print_conf(service)