Page MenuHomePhabricator

Implement nrpe config parser to easily hook into Puppet managed checks
Closed, ResolvedPublic

Description

Puppet already configures a number of nrpe Icinga checks in /etc/nagios/nrpe.d. Scap3 configurations should be able to reuse these checks by name.

Revisions and Commits

rMSCA Scap
Restricted Differential Revision

Event Timeline

dduvall assigned this task to mmodell.
dduvall raised the priority of this task from to Medium.
dduvall updated the task description. (Show Details)
dduvall added projects: Scap, Deployments.
dduvall moved this task from Needs triage to Services MVP on the Scap board.
dduvall added subscribers: gerritbot, bd808, Joe and 7 others.

1import ConfigParser, os
2from os import listdir
3from os.path import isfile, join
4import re
5
6def load_checks_from_nrpe_d(nrpe_d = "/etc/nagios/nrpe.d"):
7 check_commands = {}
8
9 for path in listdir(nrpe_d):
10 cfgfile = join(nrpe_d,path)
11 if not isfile(cfgfile):
12 continue
13
14 with open(cfgfile, 'r') as cfg:
15 for line in cfg:
16 line = line.lstrip()
17 if line.startswith('#'):
18 continue
19 (cmd_name, cmd_line) = line.split( "=", 1 )
20 match = re.match('command\[(.*)\]', cmd_name.lstrip())
21 if match:
22 cmd_name = match.group(1)
23 else:
24 continue
25 check_commands[cmd_name] = {
26 "type": "shell_command",
27 "name": cmd_name,
28 "cmdline": cmd_line
29 }
30 return check_commands

output:

{
  "check_raid": {
    "cmdline": "/usr/bin/sudo /usr/local/bin/check-raid.py", 
    "type": "shell_command", 
    "name": "check_raid"
  }, 
  "check_puppet_checkpuppetrun": {
    "cmdline": "/usr/bin/sudo /usr/local/lib/nagios/plugins/check_puppetrun -w 10800 -c 21600", 
    "type": "shell_command", 
    "name": "check_puppet_checkpuppetrun"
  }, 
  "check_cassandra": {
    "cmdline": "/usr/lib/nagios/plugins/check_procs -c 1:1 -u cassandra -C java -a CassandraDaemon", 
    "type": "shell_command", 
    "name": "check_cassandra"
  }, 
  "check_disk_space": {
    "cmdline": "/usr/lib/nagios/plugins/check_disk -w 6% -c 3% -l -e -A -i \"/srv/sd[a-b][1-3]\"", 
    "type": "shell_command", 
    "name": "check_disk_space"
  }, 
  "check_check_salt_minion": {
    "cmdline": "/usr/lib/nagios/plugins/check_procs -w 1: -c 1:4 --ereg-argument-array '^/usr/bin/python /usr/bin/salt-minion'", 
    "type": "shell_command", 
    "name": "check_check_salt_minion"
  }, 
  "check_root_disk_space": {
    "cmdline": "/usr/lib/nagios/plugins/check_disk -w 5% -c 2% -l -e -p /", 
    "type": "shell_command", 
    "name": "check_root_disk_space"
  }, 
  "check_check_dhclient": {
    "cmdline": "/usr/lib/nagios/plugins/check_procs -w 0:0 -c 0:0 -C dhclient", 
    "type": "shell_command", 
    "name": "check_check_dhclient"
  }, 
  "check_dpkg": {
    "cmdline": "/usr/local/lib/nagios/plugins/check_dpkg", 
    "type": "shell_command", 
    "name": "check_dpkg"
  }, 
  "check_check_eth": {
    "cmdline": "/usr/local/lib/nagios/plugins/check_eth", 
    "type": "shell_command", 
    "name": "check_check_eth"
  }, 
  "check_endpoints_restbase": {
    "cmdline": "/usr/local/lib/nagios/plugins/service_checker -t 5 127.0.0.1 http://127.0.0.1:7231/en.wikipedia.org/v1", 
    "type": "shell_command", 
    "name": "check_endpoints_restbase"
  }
}
dduvall added a revision: Restricted Differential Revision.Oct 7 2015, 11:25 PM