From 9bafc233defa3c5b1dd6a80512b62fe7397a23a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20Vysko=C4=8Dil?= <vyskocilpavel@muni.cz>
Date: Wed, 6 Feb 2019 11:32:15 +0100
Subject: [PATCH] Added services_running_check.sh

---
 README.md                 |  7 +++++++
 services_running_check.sh | 42 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100755 services_running_check.sh

diff --git a/README.md b/README.md
index cc9a4e9..44a27cb 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 0000000..b8efec4
--- /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
-- 
GitLab