Module: check_mk
Branch: master
Commit: 88bafd82f3eaf65696c68158c7ab531ff1932e7a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=88bafd82f3eaf6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Dec 9 15:46:02 2014 +0100
#1737 FIX mk_sap: Working around garbled SAP state file when multiple instances were
running parallel
---
.werks/1737 | 9 +++++++++
ChangeLog | 1 +
agents/plugins/mk_sap | 8 +++++++-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/.werks/1737 b/.werks/1737
new file mode 100644
index 0000000..b3ba801
--- /dev/null
+++ b/.werks/1737
@@ -0,0 +1,9 @@
+Title: mk_sap: Working around garbled SAP state file when multiple instances were running
parallel
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.5i7
+Date: 1418136328
+Class: fix
+
+
diff --git a/ChangeLog b/ChangeLog
index 1572a3a..47e6f17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -155,6 +155,7 @@
* 1748 FIX: win_dhcp_pools: fix naming of WATO rules and informal WARN/CRIT levels in
performance data
* 1735 FIX: oracle_instance: Inventory function deals better with old bogus agent
output
* 1736 FIX: lparstat_aix: Trying to deal with more kind of lparstat output...
+ * 1737 FIX: mk_sap: Working around garbled SAP state file when multiple instances
were running parallel
Multisite:
* 1508 Allow input of plugin output and perfdata when faking check results...
diff --git a/agents/plugins/mk_sap b/agents/plugins/mk_sap
index 36509a3..55adffe 100755
--- a/agents/plugins/mk_sap
+++ b/agents/plugins/mk_sap
@@ -486,7 +486,13 @@ try:
# Only write the state file once per run. And only when it has been changed
if state_file_changed:
- file(STATE_FILE, 'w').write(repr(states))
+ import fcntl
+ new_file = STATE_FILE + '.new'
+ fd = os.open(new_file, os.O_WRONLY | os.o_CREAT)
+ fcntl.flock(fd, fcntl.LOCK_EX)
+ os.write(fd, repr(states))
+ os.close(fd)
+ os.rename(STATE_FILE+'.new', STATE_FILE)
except Exception, e:
sys.stderr.write('ERROR: Unhandled exception (%s)\n' % e)