Module: check_mk
Branch: master
Commit: a0e521c4757eec84e60de34e59ad2abf2e15f562
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a0e521c4757eec…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Oct 26 11:58:38 2015 +0100
Warning police: Fixed signed/unsigned confusion (in a slightly hacky way).
---
livestatus/src/LogCache.cc | 10 +++++-----
livestatus/src/LogEntry.h | 2 +-
livestatus/src/waittriggers.h | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/livestatus/src/LogCache.cc b/livestatus/src/LogCache.cc
index 4b90914..f5bb267 100644
--- a/livestatus/src/LogCache.cc
+++ b/livestatus/src/LogCache.cc
@@ -219,7 +219,7 @@ void LogCache::dumpLogfiles()
*/
void LogCache::handleNewMessage(Logfile *logfile, time_t since __attribute__ ((__unused__)), time_t until __attribute__ ((__unused__)), unsigned logclasses)
{
- if ( ++num_cached_log_messages <= _max_cached_messages )
+ if ( static_cast<unsigned long>(++num_cached_log_messages) <= _max_cached_messages )
return; // current message count still allowed, everything ok
/* Memory checking an freeing consumes CPU ressources. We save
@@ -228,7 +228,7 @@ void LogCache::handleNewMessage(Logfile *logfile, time_t since __attribute__ ((_
memory can be freed. We do this by suppressing the check when
the number of messages loaded into memory has not grown
by at least CHECK_MEM_CYCLE messages */
- if (num_cached_log_messages < _num_at_last_check + CHECK_MEM_CYCLE)
+ if (static_cast<unsigned long>(num_cached_log_messages) < _num_at_last_check + CHECK_MEM_CYCLE)
return; // Do not check this time
// [1] Begin by deleting old logfiles
@@ -244,7 +244,7 @@ void LogCache::handleNewMessage(Logfile *logfile, time_t since __attribute__ ((_
if (log->numEntries() > 0) {
num_cached_log_messages -= log->numEntries();
log->flush(); // drop all messages of that file
- if (num_cached_log_messages <= _max_cached_messages) {
+ if (static_cast<unsigned long>(num_cached_log_messages) <= _max_cached_messages) {
// remember the number of log messages in cache when
// the last memory-release was done. No further
// release-check shall be done until that number changes.
@@ -269,7 +269,7 @@ void LogCache::handleNewMessage(Logfile *logfile, time_t since __attribute__ ((_
debug("Freeing classes 0x%02x of file %s", ~logclasses, log->path());
long freed = log->freeMessages(~logclasses); // flush only messages not needed for current query
num_cached_log_messages -= freed;
- if (num_cached_log_messages <= _max_cached_messages) {
+ if (static_cast<unsigned long>(num_cached_log_messages) <= _max_cached_messages) {
_num_at_last_check = num_cached_log_messages;
return;
}
@@ -287,7 +287,7 @@ void LogCache::handleNewMessage(Logfile *logfile, time_t since __attribute__ ((_
debug("Flush newer log, msgs %d", log->numEntries());
num_cached_log_messages -= log->numEntries();
log->flush();
- if (num_cached_log_messages <= _max_cached_messages) {
+ if (static_cast<unsigned long>(num_cached_log_messages) <= _max_cached_messages) {
_num_at_last_check = num_cached_log_messages;
return;
}
diff --git a/livestatus/src/LogEntry.h b/livestatus/src/LogEntry.h
index af32237..8f2b72e 100644
--- a/livestatus/src/LogEntry.h
+++ b/livestatus/src/LogEntry.h
@@ -34,7 +34,7 @@
#define LOGCLASS_STATE 6 // initial or current states
#define LOGCLASS_TEXT 7 // specific text passages. e.g "logging initial states"
// TODO: This LOGCLASS sets different logclasses on match -> fix this
-#define LOGCLASS_INVALID -1 // never stored
+#define LOGCLASS_INVALID 0x7fffffff // never stored
#define LOGCLASS_ALL 0xffff
#include "nagios.h"
diff --git a/livestatus/src/waittriggers.h b/livestatus/src/waittriggers.h
index 8d3d389..b468a76 100644
--- a/livestatus/src/waittriggers.h
+++ b/livestatus/src/waittriggers.h
@@ -27,7 +27,7 @@
#include "pthread.h"
-#define WT_NONE -1
+#define WT_NONE 0x7fffffff
#define WT_ALL 0
#define WT_CHECK 1
#define WT_STATE 2
Module: check_mk
Branch: master
Commit: 9784cb4292615dd2ef77eaff23b691028f4ff208
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9784cb4292615d…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Oct 25 18:42:33 2015 +0100
Code cleanup: get rid of import struct in checks
---
checks/fc_port | 5 +++--
checks/mcdata_fcport | 10 +---------
modules/check_mk_base.py | 12 ++++++++++++
3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/checks/fc_port b/checks/fc_port
index e416f4b..69e6831 100644
--- a/checks/fc_port
+++ b/checks/fc_port
@@ -86,14 +86,15 @@ def fc_port_getitem(num_ports, index, portname):
itemname += portname.strip()
return itemname
+
def fc_parse_counter(value):
# The counters are sent via SNMP as OCTETSTR, which is converted to
# a byte string by Check_MKs SNMP code. The counters seem to be
# 64 bit big endian values, which are converted to integers here
if len(value) == len("00 00 00 0C 8F 70 DD 74"):
value = "".join(map(chr, [ eval("0x" + v) for v in value.split() ]))
- import struct
- return int(struct.unpack('>Q', value)[0])
+ return binstring_to_int(value)
+
def inventory_fc_port(info):
if not info:
diff --git a/checks/mcdata_fcport b/checks/mcdata_fcport
index 4715ca9..fbe0394 100644
--- a/checks/mcdata_fcport
+++ b/checks/mcdata_fcport
@@ -28,15 +28,7 @@ mcdata_fcport_speedbits = { "2": '1000000000', "3": '2000000000' }
mcdata_fcport_opstatus = { "1" : "1", "2": "2", "3": "testing", "4": "faulty" }
def mcdata_bin_to_64(bin):
- # McData encodes 64 bit counters as big endian HEX strings,
- # e.g. Hex-STRING: 00 00 00 01 AC C2 8C EE. Check_MK converts
- # such strings into binary Python strings
- value = 0
- mult = 1
- for byte in bin[::-1]:
- value += mult * ord(byte)
- mult *= 256
- return str(value)
+ return str(binstring_to_int(bin))
def mcdata_fcport_convert_to_if64(info):
return map(mcdata_fcport_convert_line_to_if64, info)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 9986616..6d743ca 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -2119,6 +2119,18 @@ def savefloat(f):
except:
return 0.0
+# Convert a string to an integer. This is done by consideren the string to by a
+# little endian byte string. Such strings are sometimes used by SNMP to encode
+# 64 bit counters without needed COUNTER64 (which is not available in SNMP v1)
+def binstring_to_int(binstring):
+ value = 0
+ mult = 1
+ for byte in binstring[::-1]:
+ value += mult * ord(byte)
+ mult *= 256
+ return value
+
+
# Takes bytes as integer and returns a string which represents the bytes in a
# more human readable form scaled to GB/MB/KB
# The unit parameter simply changes the returned string, but does not interfere