Module: check_mk
Branch: master
Commit: 92c39da54421db9200abcb76813b96526e61e87a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=92c39da54421db…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Tue Apr 12 17:05:17 2016 +0200
3119 mssql: fixed counter calculation when caching plugin output
---
.werks/3119 | 11 +++++++++++
ChangeLog | 1 +
agents/windows/plugins/mssql.vbs | 7 ++++++-
checks/mssql_counters | 25 +++++++++++++++++++++++--
checks/mssql_tablespaces | 2 +-
5 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/.werks/3119 b/.werks/3119
new file mode 100644
index 0000000..25a9fdc
--- /dev/null
+++ b/.werks/3119
@@ -0,0 +1,11 @@
+Title: mssql: fixed counter calculation when caching plugin output
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.9i1
+Date: 1460473140
+Class: feature
+
+Previously, the mssql plugin output could not be cached as counter calculations were
based on the
+time the output was interpreted and thus would produce incorrect results.
+This has now been fixed by adding a timestamp from the mssql server to the agent output.
diff --git a/ChangeLog b/ChangeLog
index 9e6cce9..0994cf3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -50,6 +50,7 @@
* 3311 apc_netbotz_sensors, apc_netbotz_sensors.dewpoint,
apc_netbotz_sensors.humidity, apc_netbotz_other_sensors: new checks for APC Netbotz
devices which support the NETBOTZV2 MIB
* 3115 logwatch: made check cluster-able...
* 3312 check_ssh: service description can be set
+ * 3119 mssql: fixed counter calculation when caching plugin output...
* 3073 FIX: windows agent: relative paths to mrpe scripts are now treated as relative
to the agent installation directory...
* 3061 FIX: mk_jolokia: Fixed debugging of the agent plugin
* 3074 FIX: windows agent: fixed incorrect values for 32-bit performance counters
diff --git a/agents/windows/plugins/mssql.vbs b/agents/windows/plugins/mssql.vbs
index 49a2572..24df3ad 100644
--- a/agents/windows/plugins/mssql.vbs
+++ b/agents/windows/plugins/mssql.vbs
@@ -212,10 +212,15 @@ For Each instId In instIds.Keys
CONN.Open
' Get counter data for the whole instance
+ addOutput( "<<<mssql_counters>>>" )
+ RS.Open "SELECT GETUTCDATE() as utc_date", CONN
+ addOutput( "None utc_time None " & RS("utc_date") )
+ RS.Close
+
RS.Open "SELECT counter_name, object_name, instance_name, cntr_value "
& _
"FROM sys.dm_os_performance_counters " & _
"WHERE object_name NOT LIKE '%Deprecated%'", CONN
- addOutput( "<<<mssql_counters>>>" )
+
Dim objectName, counterName, instanceName, value
Do While NOT RS.Eof
objectName = Replace(Replace(Trim(RS("object_name")), " ",
"_"), "$", "_")
diff --git a/checks/mssql_counters b/checks/mssql_counters
index c930837..66779c2 100644
--- a/checks/mssql_counters
+++ b/checks/mssql_counters
@@ -133,10 +133,28 @@ check_info['mssql_counters.cache_hits'] = {
# | |
# '----------------------------------------------------------------------'
+
+def mssql_time_from_counter(info):
+ for line in info:
+ if line[1] == "utc_time":
+ # mssql returns localized format. great! let's try ...
+ try:
+ # ... iso 8601
+ return utc_mktime(time.strptime("
".join(line[3:]).split(".")[0],
+ "%Y-%m-%d %H:%M:%S"))
+ except ValueError:
+ # ... german
+ return utc_mktime(time.strptime(" ".join(line[3:]),
+ "%d.%m.%Y %H:%M:%S"))
+ return None
+
def check_mssql_counters_transactions(item, params, info):
output = []
perfdata = []
- now = time.time()
+ now = mssql_time_from_counter(info)
+ if now is None:
+ now = time.time()
+
for line in info:
if mssql_counters_item(line, False) != item:
continue
@@ -170,7 +188,10 @@ def check_mssql_counters_locks(item, params, info):
state = 0
output = []
perfdata = []
- now = time.time()
+ now = mssql_time_from_counter(info)
+ if now is None:
+ now = time.time()
+
for line in info:
if mssql_counters_item(line, False) != item:
continue
diff --git a/checks/mssql_tablespaces b/checks/mssql_tablespaces
index c9061f4..5118195 100644
--- a/checks/mssql_tablespaces
+++ b/checks/mssql_tablespaces
@@ -50,7 +50,7 @@ def inventory_mssql_tablespaces(info):
inventory = []
for line in info:
if len(line) > 1:
- inventory.append((line[0] + ' ' + line[1],
'mssql_tablespace_default_levels'))
+ inventory.append((line[0] + ' ' + line[1],
'mssql_tablespace_default_levels'))
return inventory
def check_mssql_tablespaces(item, params, info):