monitoring stuff
This commit is contained in:
parent
78d2499b46
commit
f3f624be1f
6 changed files with 38 additions and 16 deletions
|
@ -2,11 +2,7 @@
|
|||
|
||||
UNKNOWN=3
|
||||
|
||||
if [ -z "$SSHMON_TEST" ]
|
||||
then
|
||||
echo 'check_by_sshmon: Env SSHMON_TEST missing' >&2
|
||||
exit $UNKNOWN
|
||||
elif [ -z "$SSHMON_COMMAND" ]
|
||||
if [ -z "$SSHMON_COMMAND" ]
|
||||
then
|
||||
echo 'check_by_sshmon: Env SSHMON_COMMAND missing' >&2
|
||||
exit $UNKNOWN
|
||||
|
@ -16,7 +12,14 @@ then
|
|||
exit $UNKNOWN
|
||||
fi
|
||||
|
||||
ssh sshmon@"$SSHMON_HOST" "sudo $SSHMON_COMMAND"
|
||||
if [ -z "$SSHMON_SUDO" ]
|
||||
then
|
||||
PREFIX=""
|
||||
else
|
||||
PREFIX="sudo "
|
||||
fi
|
||||
|
||||
ssh sshmon@"$SSHMON_HOST" "$PREFIX$SSHMON_COMMAND"
|
||||
|
||||
exitcode=$?
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ object CheckCommand "sshmon" {
|
|||
|
||||
command = [ "/usr/lib/nagios/plugins/check_by_sshmon" ]
|
||||
|
||||
env.SSHMON_TEST = "1234"
|
||||
env.SSHMON_COMMAND = "$command$"
|
||||
env.SSHMON_HOST = "$address$"
|
||||
env.SSHMON_SUDO = "$sudo$"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
defaults = {
|
||||
'monitoring': {
|
||||
'services': {
|
||||
'test': {
|
||||
'vars.command': '/bin/ls /',
|
||||
},
|
||||
# 'test': {
|
||||
# 'vars.command': '/bin/ls /',
|
||||
# 'vars.sudo': True,
|
||||
# },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -50,6 +51,7 @@ def user(metadata):
|
|||
conf['vars.command']
|
||||
for conf in metadata.get('monitoring/services').values()
|
||||
if conf['check_command'] == 'sshmon'
|
||||
and conf.get('vars.sudo', None)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -122,8 +122,8 @@ def monitoring(metadata):
|
|||
return {
|
||||
'monitoring': {
|
||||
'services': {
|
||||
f'HTTP {hostname}': {
|
||||
'vars.command': f"""/usr/bin/curl -X GET {quote(hostname + vhost.get('check_path', ''))} -IL --fail"""
|
||||
hostname: {
|
||||
'vars.command': f"/usr/bin/curl -X GET -IL --fail {quote(hostname + vhost.get('check_path', ''))}",
|
||||
}
|
||||
for hostname, vhost in metadata.get('nginx/vhosts').items()
|
||||
},
|
||||
|
|
|
@ -58,7 +58,7 @@ def monitoring(metadata):
|
|||
'monitoring': {
|
||||
'services': {
|
||||
f'{name}.timer': {
|
||||
'vars.command': f'/usr/lib/nagios/plugins/check_systemd_timer {name}'
|
||||
'vars.command': f'/usr/lib/nagios/plugins/check_systemd_timer {name}',
|
||||
}
|
||||
for name in metadata.get('systemd-timers')
|
||||
},
|
||||
|
|
|
@ -11,7 +11,7 @@ defaults = {
|
|||
)
|
||||
def units(metadata):
|
||||
units = {}
|
||||
|
||||
|
||||
for name, config in metadata.get('systemd/units').items():
|
||||
if '/' in name:
|
||||
continue
|
||||
|
@ -47,10 +47,10 @@ def units(metadata):
|
|||
)
|
||||
def services(metadata):
|
||||
services = {}
|
||||
|
||||
|
||||
for name, config in metadata.get('systemd/services').items():
|
||||
extension = name.split('.')[-1]
|
||||
|
||||
|
||||
if extension not in ['timer', 'service', 'mount', 'swap']:
|
||||
raise Exception(f'unknown extension: {extension}')
|
||||
|
||||
|
@ -59,3 +59,20 @@ def services(metadata):
|
|||
'services': services,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@metadata_reactor.provides(
|
||||
'monitoring/services',
|
||||
)
|
||||
def monitoring(metadata):
|
||||
return {
|
||||
'monitoring': {
|
||||
'services': {
|
||||
name: {
|
||||
'vars.command': f"/bin/sh -c '/usr/bin/systemctl is-failed {name} && /usr/bin/systemctl status {name} && exit 2 || exit 0'"
|
||||
}
|
||||
for name in metadata.get('systemd/units')
|
||||
if name.endswith('.service')
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue