Plugin for owfs available

Hello,

I’ve been searching for three days for a plugin to import temperature data from a 1-wire installation into Checkmk. Is it really possible that no plugin for OWFS has been released yet?

It’s certainly not that complicated, but that’s no reason to develop it again.

Thanks for your help,

Ja_n

Hello Ja_n and welcome to the forum.
Some of teh temperature modules can be captured via SNMP.
Here is an example of an Inveo device which uses 1-wire as temperature sensors.

#/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Inveo Monitoring
"""

from typing import Dict, Any, Mapping, Sequence, List
from cmk.agent_based.v2 import (
    SNMPSection,
    SNMPTree,
    StringTable,
    DiscoveryResult,
    CheckResult,
    Service,
    startswith,
    get_value_store,
    CheckPlugin,
)
from cmk.plugins.lib.temperature import check_temperature
from pprint import pprint

ParsedSection = Mapping[str, tuple[str, str]]
Section = Mapping[str, dict[str, float]]


def parse_inveo_temp(string_table: List[StringTable]) -> ParsedSection:
    parsed = {}
    parsed['temperature'] = int(string_table[0][0][0])
    return parsed

snmp_section_inveo_temp = SNMPSection(
    name="inveo_temp",
    parse_function=parse_inveo_temp,
    fetch=[
        SNMPTree(
            base='.1.3.6.1.4.1.42814.14.3.5',
            oids=[
                '3', # sensor nr 1 temp * 10
            ],
        ),
    ],
    detect=startswith(".1.3.6.1.2.1.1.2.0", ".1.3.6.1.4.1.42814.14"),
)

def discover_inveo_temp(section: Section) -> DiscoveryResult:
    yield Service(item="1")

def check_inveo_temp(item: str, params: Sequence[Mapping[str, Any]], section: Section) -> CheckResult:
    if 'temperature' in section:
        value_store = get_value_store()
        temp = float(section['temperature']) / 10
        yield from check_temperature(
                temp,
                params,
                value_store=value_store,
                unique_name="inveo_temp.%s" % item
        )

check_plugin_inveo_temp = CheckPlugin(
        name="inveo_temp",
        service_name="Sensor %s",
        discovery_function=discover_inveo_temp,
        check_function=check_inveo_temp,
        check_default_parameters={},
        check_ruleset_name="temperature",
)

In relation to the MIB you device canhave more the one connector for 1-wire temp, so you need to add next oid.

RG, Christian

1 Like

Hello,

I have a raspberry with one-wire Server is installed. Here is in the folder /mnt/1-wire/sensoraddress/temperature* published. Now I want read this values with a plugin and send it to the checkmk.

I think it’s already in use very often.

BG Ja_n

Hi.
I wrote a plugin like this:

#!/bin/bash
devpath="/sys/bus/w1/devices"
ch=1
echo "<<<onewire>>>"
if [ -d $devpath ]
then
    for x in $(ls -d $devpath/28*)
    do
        sensor=$(basename $x)
        temp=$(cat $devpath/$sensor/w1_slave | grep "t=" | cut -d '=' -f2 | awk ' { printf "%3.2f" , ( $1 / 1000 ) } ')
        echo "temp T${ch} $temp"
        ch=$(( $ch + 1 ))
    done

fi

And also a check like this (Version 1.2.8 )

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#---------------------------------------------------------------------#
# Dateiname : onewire                                                 #
#---------------------------------------------------------------------#
onewire_temp_default_values = (45, 55)

def inventory_onewire_temp(info):
   # beginn with empty list
   inventory = []
   for line in info:
      select = line[0]
      ch = line [1]
      temp = line [2]
      
      if select == "temp":
          inventory.append( (ch, "onewire_temp_default_values") )

   return inventory

def check_onewire_temp(item, params, info):
   warn, crit = params

   for line in info:
      if line[1] == item and line[0] == "temp":
          temp = float(line[2])
          perfdata = [ ("temp", temp, warn, crit, 45, 55) ]
          if temp > crit:
             return (2, "Critical Temperature at %-3.1f Grad Celsius" % temp, perfdata)
          elif temp > warn:
             return (1, "Warning Temperature at %-3.1f Grad Celsius" % temp, perfdata)
          else :
             return (0, "Normal Temperature at %-3.1f Grad Celsius" % temp, perfdata)
   return(3, "Temperature %s not found in agent output" % item)  
      

check_info["onewire.temp"] = {
    'check_function':        check_onewire_temp,
    'inventory_function':    inventory_onewire_temp,
    'group':                 'onewire_temperature',
    'service_description':   'OneWire Temperature %s',
    'has_perfdata':          True,
}

OKay. Thank you for sharing!