Module: check_mk
Branch: master
Commit: 5f146cda13e5b887944698546fadfd7e7bd38fb0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5f146cda13e5b8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Sep 15 13:47:05 2015 +0200
siemens_plc_cpu: Added new check for monitoring the state of the CPU of Siemens PLC
devices
---
agents/special/agent_siemens_plc | 8 ++++++--
checkman/siemens_plc_cpu | 18 ++++++++++++++++++
checks/siemens_plc | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/agents/special/agent_siemens_plc b/agents/special/agent_siemens_plc
index 7d93df2..7541add 100755
--- a/agents/special/agent_siemens_plc
+++ b/agents/special/agent_siemens_plc
@@ -27,7 +27,8 @@
import getopt, sys, socket, traceback, re, pprint
import snap7
from snap7.util import *
-from snap7.snap7types import S7AreaPE, S7AreaPA, S7AreaMK, S7AreaDB, S7AreaCT, S7AreaTM
+from snap7.snap7types import S7AreaPE, S7AreaPA, S7AreaMK, S7AreaDB, \
+ S7AreaCT, S7AreaTM
def usage():
sys.stderr.write("""Check_MK Siemens PLC Agent
@@ -183,13 +184,16 @@ datatypes = {
}
unhandled_error = False
-sys.stdout.write("<<<siemens_plc>>>\n")
for device in devices:
try:
client = snap7.client.Client()
client.connect(device['host_address'], device['rack'],
device['slot'], device['port'])
+ sys.stdout.write("<<<siemens_plc_cpu_state>>>\n")
+ sys.stdout.write(client.get_cpu_state()+"\n")
+
+ sys.stdout.write("<<<siemens_plc>>>\n")
# We want to have a minimum number of reads. We try to only use
# a single read and detect the memory area to fetch dynamically
# based on the configured values
diff --git a/checkman/siemens_plc_cpu b/checkman/siemens_plc_cpu
new file mode 100644
index 0000000..1235153
--- /dev/null
+++ b/checkman/siemens_plc_cpu
@@ -0,0 +1,18 @@
+title: Siemens PLC: CPU state
+agents: siemens_plc
+catalog: hw/other
+license: GPL
+distribution: check_mk
+description:
+ Monitors the current CPU state of Siemens PLC (SPS) devices.
+
+ You need to use and configure the special agent {agent_siemens_plc} which is using the
SNAP7
+ library to communicate with the Siemens PLC. When you are using OMD, everything is
already
+ installed and configured. In manual setups, you will need to ensure that the snap7
library
+ and python module {snap7} are installed.
+
+ The CPU state can either be reported as running ({OK}), stopped ({CRITICAL}) and
unknown
+ ({UNKNOWN}).
+
+inventory:
+ One check for each device is created automatically.
diff --git a/checks/siemens_plc b/checks/siemens_plc
index 3c44729..97e87b4 100644
--- a/checks/siemens_plc
+++ b/checks/siemens_plc
@@ -246,3 +246,40 @@ check_info['siemens_plc.info'] = {
"service_description" : "Info %s",
"has_perfdata" : False,
}
+
+#.
+# .--CPU-State-----------------------------------------------------------.
+# | ____ ____ _ _ ____ _ _ |
+# | / ___| _ \| | | | / ___|| |_ __ _| |_ ___ |
+# | | | | |_) | | | |____\___ \| __/ _` | __/ _ \ |
+# | | |___| __/| |_| |_____|__) | || (_| | || __/ |
+# | \____|_| \___/ |____/ \__\__,_|\__\___| |
+# | |
+# +----------------------------------------------------------------------+
+# | |
+# '----------------------------------------------------------------------'
+
+def inventory_siemens_plc_cpu_state(info):
+ return [ (None, None) ]
+
+
+def check_siemens_plc_cpu_state(_no_item, _no_params, info):
+ try:
+ state = info[0][0]
+ except IndexError:
+ return
+
+ if state == "S7CpuStatusRun":
+ return 0, "CPU is running"
+ elif state == "S7CpuStatusStop":
+ return 2, "CPU is stopped"
+ else:
+ return 3, "CPU is in unknown state"
+
+
+check_info['siemens_plc_cpu_state'] = {
+ "inventory_function" : inventory_siemens_plc_cpu_state,
+ "check_function" : check_siemens_plc_cpu_state,
+ "service_description" : "CPU state",
+ "has_perfdata" : False,
+}