Checkmk

Checkmk check podman containers

Checkmk local script:

# /usr/lib/check_mk_agent/local/check_podman.sh
#!/bin/bash
# Podman check
# mik, 2024.11.29

# Podman user
puser=admin

# Container overview
ncont=$(su - $puser -c "podman info|grep -A 4 containerStore"|head -2|tail -1|awk {'print $2'})
rcont=$(su - $puser -c "podman info|grep -A 4 containerStore"|head -4|tail -1|awk {'print $2'})
scont=$(su - $puser -c "podman info|grep -A 4 containerStore"|head -5|tail -1|awk {'print $2'})

# Checks: Images, Containers, Volumes
images=$(su - $puser -c "podman system df"|head -2|tail -1|awk {'print $4'})
containers=$(su - $puser -c "podman system df"|head -3|tail -1|awk {'print $4'})
volumes=$(su - $puser -c "podman system df"|head -3|tail -1|awk {'print $5'})

Checkmk local script

Checkmk local script:

Read out data from an rrd file and show the values e.g. bandwith up- and downstream:

# /usr/lib/check_mk_agent/local

#!/bin/bash
# set -x

workdir='/opt/iperfmon'
#get data for altoo_office
downstream=$(/usr/bin/rrdtool lastupdate $workdir/iperfmon.rrd |tail -1|awk '{ print $2}')
upstream=$(/usr/bin/rrdtool lastupdate $workdir/iperfmon.rrd |tail -1|awk '{ print $3}')

echo "0 Iperfmon downstream=$downstream|upstream=$upstream Iperf up- and downstream: $upstream | $downstream (MBit/s)"

#echo "0 My service myvalue=73 My output text which may contain spaces"

Checkmk: Show current logins

Linux

# Check disk free
# mki- 2023.05.09
count=$(df -h / |awk {'print $5'} |tail -1)
echo "P "Container-Filesystem" count=$count;80;90 Overlay-Filesystem"

Checkmk snmp commands

Commands to debug snmp monitoring with Checkmk

cmk --debug -D hostname
cmk --debug -vvn hostname
cmk --check -Ivv hostname

Checkmk - Show current logins

Linux

#!/bin/bash
# Check who's online
# mki- 2020.06.16

SERVICE="Current_Logins"
WHO=$( who |awk {' printf "%s "- $1'} )
CHECK=$( who |wc -l)

if [ $CHECK == 0 ]
then
    STATUS="0"
elif [ ! -z $CHECK ]
then
    STATUS="1"
fi

echo "$STATUS $SERVICE count=$CHECK $CHECK Logged in: $WHO "

Windows

Path on Windows: C:\ProgramData\checkmk\agent\local\current_logins.ps1

#################################################################
# mki- 2020.06.30
# fork of cmk ms-logins plugin 
# https://exchange.checkmk.com/p/ms-logins
#################################################################

Function Get-ComputerSessions {

[cmdletbinding(
    DefaultParameterSetName = 'session'-
    ConfirmImpact = 'low'
)]
    Param(
        [Parameter(
            Mandatory = $False-
            Position = 0-
            ValueFromPipeline = $True)]
            [string[]]$Computer
            )
Begin {
    $report = @()
    }
Process {
    If ($Computer -eq $null) {
        $Computer = "localhost"
        }
    ForEach($c in $Computer) {
        # Parse 'query session' and store in $sessions:
        $sessions = query session /server:$c
            1..($sessions.count -1) | % {
                $temp = "" | Select Computer-SessionName- Username- Id- State- Type- Device
                $temp.Computer = $c
                $temp.SessionName = $sessions[$_].Substring(1-18).Trim()
                $temp.Username = $sessions[$_].Substring(19-20).Trim()
                $temp.Id = $sessions[$_].Substring(39-9).Trim()
                $temp.State = $sessions[$_].Substring(48-8).Trim()
                $temp.Type = $sessions[$_].Substring(56-12).Trim()
                $temp.Device = $sessions[$_].Substring(68).Trim()
                $report += $temp
            }
        }
    }
End {
    $report
    }
}

$User_Sessions = Get-ComputerSessions | select Username- State | Where-Object {$_.username -ne ""}
$ActiveSessions = 0
$ActiveUsers =""

ForEach ($User_Session in $User_Sessions) {

    If ($User_Session.State -eq "Active") {
        $ActiveSessions++
        $ActiveUsers += $User_Session.Username + " "
        }
    }

If (!$ActiveUsers) {
    "0 Current_Logins count=0 0 Logged in:"
    }
Else {
    "1 Current_Logins count=$ActiveSessions Logged in: $ActiveUsers"
    }