[Check_mk (english)] Write SNMP Check

David Callahan dwcallahan at gmail.com
Thu Jul 14 19:40:33 CEST 2016


I realize this is not the best place to post this question as its mainly a
python question.  Maybe someone will be kind enough to give there 2 cents.
The OID in this check always results in a decimal number.  I did figure out
that if I change the int to float I get the right first part of the output
but anything after the decimal is lost.

Bad.
RX_Signal_Carrier = int(info[0][0]) / 1
ValueError: invalid literal for int() with base 10: '14.2'

Good but after the decimal is lost.
RX_Signal_Carrier = float(info[0][0]) / 1


#!/usr/bin/python

idc_rx_carrier_default_levels = (0.0, 100.0)

def check_idc_rx_carrier(item, params, info):
     warn, crit = params
     RX_Signal_Carrier = float(info[0][0]) / 1
     infotext = " - %sdb" % RX_Signal_Carrier
     warn, crit = params
     perfdata = [("RX C/N", RX_Signal_Carrier, warn, crit, 0.0, 10.0)]
     if RX_Signal_Carrier >= crit:
         infotext = "CRIT - %ddb (critical at %ddb)" % (RX_Signal_Carrier,
crit)
         return (2, infotext, perfdata)
     elif RX_Signal_Carrier <= warn:
         infotext = "WARN - %ddb (warning at %ddb)" % (RX_Signal_Carrier,
warn)
         return (1, infotext, perfdata)
     else:
         infotext = "OK - %ddb" % RX_Signal_Carrier
         return (0, infotext, perfdata)

check_info["idc_rx_carrier"] = {
     "check_function"        : check_idc_rx_carrier,
     "inventory_function"    : lambda info: [(None,
"idc_rx_carrier_default_levels")],
     "service_description"   : "RX C/N",
     "has_perfdata"          : True,
     "group"                 : "idc",
     "snmp_scan_function"    : lambda oid:
oid(".1.3.6.1.4.1.3602.1.1.13.2.1.*"),
     "snmp_info"             : ( ".1.3.6.1.4.1.3602.1.1.13.2.1.3", [ "3.0"
]),
}




--
Dave Callahan

On Mon, Jul 11, 2016 at 11:37 AM, David Callahan <dwcallahan at gmail.com>
wrote:

> Marcel,
>
> Thanks for this info but without knowing much about python I'm still have
> some issues.  Here is the output.
>
> OMD[wxii]:~$ cmk --debug -npvvvvv --checks idc_rx_carrier WXIIS2X1
> Check_mk version 1.2.8p4
>    Running snmpbulkwalk -v2c -c 'public' -m '' -M '' -t 15.00 -r 3 -Cc -OQ
> -OU -On -Ot 192.168.158.194 .1.3.6.1.4.1.3602.1.1.13.2.1.3.4.0
> Traceback (most recent call last):
>   File "/omd/sites/wxii/share/check_mk/modules/check_mk.py", line 5283, in
> <module>
>     exit_status = do_check(hostname, ipaddress, check_types)
>   File "/omd/sites/wxii/share/check_mk/modules/check_mk_base.py", line
> 1198, in do_check
>     do_all_checks_on_host(hostname, ipaddress, only_check_types)
>   File "/omd/sites/wxii/share/check_mk/modules/check_mk_base.py", line
> 1460, in do_all_checks_on_host
>     result = sanitize_check_result(check_function(item, params, info),
> check_uses_snmp(checkname))
>   File "/omd/sites/wxii/local/share/check_mk/checks/idc_rx_carrier", line
> 7, in check_idc_rx_carrier
>     RX_Signal_Carrier = int(info[0][0]) / 1
> ValueError: invalid literal for int() with base 10: '14.2'
>
> Here is the code used.
>
> #!/usr/bin/python
>
> idc_rx_carrier_default_levels = (0.0, 100.0)
>
> def check_idc_rx_carrier(item, params, info):
>      warn, crit = params
>      RX_Signal_Carrier = int(info[0][0]) / 1
>      infotext = " - %sdb" % RX_Signal_Carrier
>      warn, crit = params
>      perfdata = [("RX C/N", RX_Signal_Carrier, warn, crit, 0.0, 10.0)]
>      if RX_Signal_Carrier >= crit:
>          infotext = "CRIT - %ddb (critical at %ddb)" % (RX_Signal_Carrier,
> crit)
>          return (2, infotext, perfdata)
>      elif RX_Signal_Carrier <= warn:
>          infotext = "WARN - %ddb (warning at %ddb)" % (RX_Signal_Carrier,
> warn)
>          return (1, infotext, perfdata)
>      else:
>          infotext = "OK - %ddb" % RX_Signal_Carrier
>          return (0, infotext, perfdata)
>
> check_info["idc_rx_carrier"] = {
>      "check_function"        : check_idc_rx_carrier,
>      "inventory_function"    : lambda info: [(None,
> "idc_rx_carrier_default_levels")],
>      "service_description"   : "RX C/N",
>      "has_perfdata"          : True,
>      "group"                 : "idc",
>      "snmp_scan_function"    : lambda oid:
> oid(".1.3.6.1.4.1.3602.1.1.13.2.1.*"),
>      "snmp_info"             : ( ".1.3.6.1.4.1.3602.1.1.13.2.1.3", [ "3.0"
> ]),
> }
>
> Any help is appreciated.
>
> --
> Dave Callahan
>
> On Thu, Jun 30, 2016 at 3:14 AM, Marcel Schulte <schulte.marcel at gmail.com>
> wrote:
>
>> Hi Dave,
>>
>> we got atimestamp as hex string from our device. In order to display/use
>> it as date string we used this code:
>>
>> #####
>>             hdate = atimestamp
>>             atimestamp = "%i-%02i-%02i %02i:%02i:%02i" % ((
>>                 (ord(hdate[0])*16**2)+ord(hdate[1])),
>>                  ord(hdate[2]),
>>                  ord(hdate[3]),
>>                  ord(hdate[4]),
>>                  ord(hdate[5]),
>>                  ord(hdate[6]))
>> #####
>>
>> Maybe this helps. If it doesn't we need the exact issue: the output of
>> "check_mk --debug -npvvvvv --checks idc_rx_carrier AFFECTEDHOSTNAME".
>>
>> Regards,
>> Marcel
>>
>>
>>
>> Marcel Schulte <schulte.marcel at gmail.com> schrieb am Mi., 29. Juni 2016
>> um 18:40 Uhr:
>>
>>> Hi Dave,
>>>
>>> I had the same problem with a device sending a date  as dotted octet
>>> string. I'll see if I can send the relevant code - but could last till
>>> tomorrow (I'm on way home).
>>>
>>> Regards,
>>> Marcel
>>>
>>> David Callahan <dwcallahan at gmail.com> schrieb am Mi., 29. Juni 2016
>>> 18:07:
>>>
>>>> Still having issues with this check.  When the return is OctetString
>>>> like 44.0 the I receive UNKNOWN - invalid output from agent or error
>>>> in check implementation.  Works fine if no . is in the return.
>>>>
>>>> **Code**
>>>> #!/usr/bin/python
>>>>
>>>> idc_rx_carrier_default_levels = (0.0, 100.0)
>>>>
>>>> def check_idc_rx_carrier(item, params, info):
>>>>      warn, crit = params
>>>>      RX_Signal_Carrier = int(info[0][0]) / 1
>>>>      infotext = " - %sdb" % RX_Signal_Carrier
>>>>      warn, crit = params
>>>>      perfdata = [("RX C/N", RX_Signal_Carrier, warn, crit, 0.0, 10.0)]
>>>>      if RX_Signal_Carrier >= crit:
>>>>          infotext = "CRIT - %ddb (critical at %ddb)" %
>>>> (RX_Signal_Carrier, crit)
>>>>          return (2, infotext, perfdata)
>>>>      elif RX_Signal_Carrier <= warn:
>>>>          infotext = "WARN - %ddb (warning at %ddb)" %
>>>> (RX_Signal_Carrier, warn)
>>>>          return (1, infotext, perfdata)
>>>>      else:
>>>>          infotext = "OK - %ddb" % RX_Signal_Carrier
>>>>          return (0, infotext, perfdata)
>>>>
>>>> check_info["idc_rx_carrier"] = {
>>>>      "check_function"        : check_idc_rx_carrier,
>>>>      "inventory_function"    : lambda info: [(None,
>>>> "idc_rx_carrier_default_levels")],
>>>>      "service_description"   : "RX C/N",
>>>>      "has_perfdata"          : True,
>>>>      "group"                 : "idc",
>>>>      "snmp_scan_function"    : lambda oid:
>>>> oid(".1.3.6.1.4.1.3602.1.1.13.2.1.*"),
>>>>      "snmp_info"             : ( ".1.3.6.1.4.1.3602.1.1.13.2.1.3", [
>>>> "3.0" ]),
>>>> }
>>>>
>>>> --
>>>> Dave Callahan
>>>>
>>>> On Fri, Jun 24, 2016 at 3:50 PM, David Callahan <dwcallahan at gmail.com>
>>>> wrote:
>>>>
>>>>> What might you do with the "return" is a OctetString such as 44.0?  I
>>>>> receive UNKNOWN - invalid output from agent or error in check
>>>>> implementation  .  Works fine if the return is an Integer.
>>>>>
>>>>> --
>>>>> Dave Callahan
>>>>>
>>>>> On Fri, Jun 24, 2016 at 10:42 AM, Stier, Matthew <
>>>>> Matthew.Stier at us.fujitsu.com> wrote:
>>>>>
>>>>>> I see that you are trying to setup a core ‘infotext’ string early in
>>>>>> the  check routine.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I’d removing it, and declare a complete ‘infotext’ within each branch
>>>>>> of the if/elif/else condition, customized to for that output, then the
>>>>>> ‘return’ is greatly simplified.
>>>>>>
>>>>>>
>>>>>>
>>>>>>      if RX_Signal_Level >= crit:
>>>>>>
>>>>>>          infotext = "CRIT - %d in last 5 minutes (critical at %d%%)"
>>>>>> % (RX_Signal_Level, crit)
>>>>>>
>>>>>>          return (2, infotext, perfdata)
>>>>>>
>>>>>>      elif RX_Signal_Level <= warn:
>>>>>>
>>>>>>          infotext = "WARN - %d in last 5 minutes (warning at %d%%)" %
>>>>>> (RX_Signal_Level, warn)
>>>>>>
>>>>>>          return (1, infotext, perfdata)
>>>>>>
>>>>>>      else:
>>>>>>
>>>>>>          infotext = "OK - %d in last 5 minutes" % RX_Signal_Level
>>>>>>
>>>>>>          return (0, infotext, perfdata)
>>>>>>
>>>>>>
>>>>>>
>>>>>> *From:* checkmk-en-bounces at lists.mathias-kettner.de [mailto:
>>>>>> checkmk-en-bounces at lists.mathias-kettner.de] *On Behalf Of *David
>>>>>> Callahan
>>>>>> *Sent:* Friday, June 24, 2016 9:19 AM
>>>>>> *To:* checkmk-en at lists.mathias-kettner.de
>>>>>> *Subject:* [Check_mk (english)] Write SNMP Check
>>>>>>
>>>>>>
>>>>>>
>>>>>> So I'm no Python programmer and wanted a few experts just to look at
>>>>>> this.  I was able to take the
>>>>>> https://mathias-kettner.de/checkmk_devel_snmpbased.html to write the
>>>>>> following.  This works fine but would like to add a percent symbol (%)
>>>>>> behind the plugin output (where in the picture is shows "in the last 5
>>>>>> minutes").  I would also like to add in another oid so can this be done in
>>>>>> the same check?
>>>>>>
>>>>>>
>>>>>>
>>>>>> Many thanks!
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> #!/usr/bin/python
>>>>>>
>>>>>>
>>>>>>
>>>>>> idc_rx_level_default_levels = (0, 100)
>>>>>>
>>>>>>
>>>>>>
>>>>>> def check_idc_rx_level(item, params, info):
>>>>>>
>>>>>>      warn, crit = params
>>>>>>
>>>>>>      RX_Signal_Level = int(info[0][0]) / 1
>>>>>>
>>>>>>      infotext = " - %s in last 5 minutes" % RX_Signal_Level
>>>>>>
>>>>>>      warn, crit = params
>>>>>>
>>>>>>      perfdata = [("RX Signal Level", RX_Signal_Level, warn, crit, 0,
>>>>>> 140)]
>>>>>>
>>>>>>      if RX_Signal_Level >= crit:
>>>>>>
>>>>>>          return (2, "CRIT" + infotext + " (critical at %d%%)" %
>>>>>>
>>>>>> crit, perfdata)
>>>>>>
>>>>>>      elif RX_Signal_Level <= warn:
>>>>>>
>>>>>>          return (1, "WARN" + infotext + " (warning at %d%%)" %
>>>>>>
>>>>>> warn, perfdata)
>>>>>>
>>>>>>      else:
>>>>>>
>>>>>>          return (0, "OK" + infotext, perfdata)
>>>>>>
>>>>>>
>>>>>>
>>>>>> check_info["idc_rx_level"] = {
>>>>>>
>>>>>>      "check_function"        : check_idc_rx_level,
>>>>>>
>>>>>>      "inventory_function"    : lambda info: [(None,
>>>>>>
>>>>>> "idc_rx_level_default_levels")],
>>>>>>
>>>>>>      "service_description"   : "RX Signal Level",
>>>>>>
>>>>>>      "has_perfdata"          : True,
>>>>>>
>>>>>>      "group"                 : "idc",
>>>>>>
>>>>>>      "snmp_scan_function"    : lambda oid:
>>>>>>
>>>>>> oid(".1.3.6.1.4.1.3602.1.1.13.2.1.*"),
>>>>>>
>>>>>>      "snmp_info"             : ( ".1.3.6.1.4.1.3602.1.1.13.2.1.3", [
>>>>>> "2.0" ]),
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> [image: Inline image 1]
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Dave Callahan
>>>>>>
>>>>>
>>>>>
>>>> _______________________________________________
>>>> checkmk-en mailing list
>>>> checkmk-en at lists.mathias-kettner.de
>>>> http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
>>>
>>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mathias-kettner.de/pipermail/checkmk-en/attachments/20160714/7441cc06/attachment-0001.html>


More information about the checkmk-en mailing list