Created
April 2, 2019 17:24
-
-
Save Decstasy/7c8e3092558288d4520cd690f73cd597 to your computer and use it in GitHub Desktop.
Checks server uptime on linux machines and raises critical if uptime <= 5 minutes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##### | |
# | |
# Author: Dennis Ullrich ([email protected]) | |
# | |
# Description: | |
# Checks server uptime on linux machines and raises critical if uptime <= 5 minutes. | |
# Made for icinga2 - parameters are not implemented yet. | |
# | |
# In global zone: | |
# object CheckCommand "check_uptime" { | |
# import "plugin-check-command" | |
# command = [ "/usr/local/nagios/libexec/check_uptime" ] | |
# } | |
# | |
# Service definition: | |
# apply Service "check_uptime" { | |
# display_name = "System Uptime" | |
# check_command = "check_uptime" | |
# | |
# import "generic-service" | |
# check_interval = 1m | |
# | |
# command_endpoint = host.vars.client_endpoint | |
# assign where host.vars.os == "Linux" | |
# } | |
# | |
# Changelog: | |
# 2019-02-07 V0.1: First release | |
# | |
##### | |
s_to_dhms() { | |
((d=${1}/60/60/24)) | |
((h=${1}/60/60%24)) | |
((m=${1}/60%60)) | |
((s=${1}%60)) | |
printf "%d days, %02dh:%02dm:%02ds\n" $d $h $m $s | |
} | |
read -d . uptime _ </proc/uptime || { echo "Unknown: failed to read /proc/uptime"; exit 3; } | |
UPTIME="$(s_to_dhms $uptime)" | |
if [[ $uptime -le 300 ]]; then | |
echo "CRITICAL: Machine has been rebootet in the past 5 Minutes! Uptime $UPTIME" | |
exit 2 | |
elif [[ $uptime -gt 300 ]]; then | |
echo "OK: Uptime $UPTIME" | |
exit 0 | |
else | |
echo "UNKNOWN: Weird value of $uptime" | |
exit 3 | |
fi | |
# vim: expandtab:ai:ts=2:sw=2:sts=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment