Pylint no-else-return refactoring: tenth (and so far last) set of files
[check_mk.git] / cmk_base / snmp_utils.py
blob1bec64b60eedd1d576bf9d5ae9786689ae7a8b18
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.
28 OID_END = 0 # Suffix-part of OID that was not specified
29 OID_STRING = -1 # Complete OID as string ".1.3.6.1.4.1.343...."
30 OID_BIN = -2 # Complete OID as binary string "\x01\x03\x06\x01..."
31 OID_END_BIN = -3 # Same, but just the end part
32 OID_END_OCTET_STRING = -4 # yet same, but omit first byte (assuming that is the length byte)
35 def BINARY(oid):
36 """Tell Check_MK to process this OID as binary data to the check."""
37 return "binary", oid
40 def CACHED_OID(oid):
41 """Use this to mark OIDs as being cached for regular checks,
42 but not for discovery"""
43 return "cached", oid
46 def binstring_to_int(binstring):
47 """Convert a string to an integer.
49 This is done by consideren the string to by a little endian byte string.
50 Such strings are sometimes used by SNMP to encode 64 bit counters without
51 needed COUNTER64 (which is not available in SNMP v1)."""
52 value = 0
53 mult = 1
54 for byte in binstring[::-1]:
55 value += mult * ord(byte)
56 mult *= 256
57 return value