diff --git a/README.md b/README.md index cc9a4e9478ebedabf242e8ecc6c0393d17a4fa45..44a27cb89ba308cefefc8d8d95e0507fc10b69d1 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,13 @@ Local scripts are located in /usr/lib/check_mk/local/ paths="" </pre> +### services_running_check.sh +* Attributes to be filled: +<pre> +# List of service names separated by space +services="" +</pre> + ## List of plugins Local scripts are located in /usr/lib/check_mk/plugins/ \ No newline at end of file diff --git a/services_running_check.sh b/services_running_check.sh new file mode 100755 index 0000000000000000000000000000000000000000..b8efec4923f92866e50c39276f4d08bdfde6ece6 --- /dev/null +++ b/services_running_check.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# List of service names separated by space +services="" + +for service in $services +do + serviceStatusResult=$(service $service status -v 2> /dev/null) + IFS=$'\n' + re="Active:.*" + reActive="Active: active \(running\)" + reStopped="Active: inactive \(dead\)" + + if [[ -n $serviceStatusResult ]] ; then + + for item in $serviceStatusResult + do + if [[ $item =~ $re ]]; then + serviceStatus=$item + break + fi + done + + if [[ $serviceStatus =~ $reActive ]]; then + status=0 + statustxt="Service $service is running." + else + if [[ $serviceStatus =~ $reStopped ]]; then + status=2 + statustxt="Service $service is stopped." + else + status=2 + statustxt="Service $service is in unknown state: $serviceStatus" + fi + fi + else + status=2 + statustxt="Service $service doesn't exist" + fi + + echo "$status service_running_check_$service - $statustxt" +done \ No newline at end of file