Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / cmk_base / snmp_utils.py
blob72330d10c4c842f257189649bc56d60fee9e1ba9
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 OID_END = 0 # Suffix-part of OID that was not specified
28 OID_STRING = -1 # Complete OID as string ".1.3.6.1.4.1.343...."
29 OID_BIN = -2 # Complete OID as binary string "\x01\x03\x06\x01..."
30 OID_END_BIN = -3 # Same, but just the end part
31 OID_END_OCTET_STRING = -4 # yet same, but omit first byte (assuming that is the length byte)
34 def BINARY(oid):
35 """Tell Check_MK to process this OID as binary data to the check."""
36 return "binary", oid
39 def CACHED_OID(oid):
40 """Use this to mark OIDs as being cached for regular checks,
41 but not for discovery"""
42 return "cached", oid
45 def binstring_to_int(binstring):
46 """Convert a string to an integer.
48 This is done by consideren the string to by a little endian byte string.
49 Such strings are sometimes used by SNMP to encode 64 bit counters without
50 needed COUNTER64 (which is not available in SNMP v1)."""
51 value = 0
52 mult = 1
53 for byte in binstring[::-1]:
54 value += mult * ord(byte)
55 mult *= 256
56 return value