Query Netbox with Ansible to generate an Ansible inventory

1.
Make sure you use Ansible version >= 2.10.x
pip3 install –user –upgrade pip
pip3 install –user –upgrade ansible

2.
Install pynetbox
apt install python3-pip
pip install pynetbox –upgrade

3.
Install the Ansible module
ansible-galaxy collection install netbox.netbox

4.
Simple netbox-inventory YAML
# 02-netbox-inventory.yml

plugin: netbox.netbox.nb_inventory
api_endpoint: https://netbox.heaven.grp
token: api-key
validate_certs: false
config_context: false
group-by:
  – tags

5.
Install Netbox
Follow the Netbox installation guide
https://docs.netbox.dev/en/stable/installation/
Fill in some live in there

6.
Testing the generation of the Netbox inventory via ansible-inventory
ansible-inventory -i 02-netbox-inventory.yml –list

PRTG Skript for Monitoring Ntfs Errors in Windows Eventlog

$hostname = „hostname.domainname.tld“
$threshold = 0
$days = 2
$username = „DOMAIN\administrator“

$password = „p4ssw0rd“
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force

$credentials= New-Object System.Management.Automation.PSCredential ($username, $secpasswd)

$ErrorCount = Get-WinEvent -ComputerName $hostname -ProviderName „Microsoft-Windows-Ntfs“ -Credential $credentials | Where-Object LevelDisplayName -eq
„Fehler“ | Where-Object TimeCreated -gt $((Get-Date) – (New-TimeSpan -Day $days)) | Measure-Object | Select-Object -expand Count

if ($ErrorCount -eq $threshold) {
  Write-Host „${ErrorCount}:$Errorcount event(s) for Ntfs errors on $hostname in the last $days days – OK“
}
else {
  Write-Host „${ErrorCount}:$Errorcount event(s) for Ntfs errors on $hostname in the last $days days – CRIT“
}

Elementanzahl in SMB Share

Es soll ein Check auf Filecount implementiert werden. Auf dem abzufragenden Server kann jedoch kein check_mk Agent installiert werden. Es kann jedoch mit User / Passwort / Domain auf einen UNC-Pfad zugegriffen werden. Um die Dateianzahl darüber zu ermittelt habe ich das kleine check_smb_count.sh Plugin geschrieben (/opt/omd/versions/default/lib/nagios/plugins/check_smb_count.sh):

#!/bin/bash 
# 
# Check count of lines for smbclient 
# 
# smbclient //host/share SecretPassword  -U Username -W Domainname -c ls | wc -l 
# Domain=[DOMAIN] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1] 
# 18 
# 
# (c) 2018 Steffen Berg 
#  
server="host" 
share="share1" 
user="user1" 
password="secret" 
domain="WORKGROUP" 
critical="20" 
subdir="/subdir1/subdir2/*"  

elemcountraw=`smbclient //$server/$share $password -U $user -W $domain -c "ls $subdir" 2> /dev/null | wc -l` 

elemcount=$(($elemcountraw - 4))  

if [ "$elemcount" -lt "$critical" ] then   
echo "0 SMB-ElementCount - OK SMB-ElementCount $elemcount/$critical OK"
  exit 0 
else   echo "2 SMB-ElementCount - CRITICAL SMB-ElementCount $elemcount/$critical CRIT"
  exit 2 
fi

Einbindung über /omd/sites/<site>/etc/check_mk/conf.d/legacy.mk

# Definition of the Nagios command for SMB extra_nagios_conf += r""" define command {   command_name check_smb_count   command_line /opt/omd/versions/default/lib/nagios/plugins/check_smb_count.sh } """  # Create service definition legacy_checks += [   (( "check_smb_count", "ElementCountSMB", True), [ "host" ] ), ]

check_mk Powershell KV-Safenet Status eines Routers abfragen – KAMP-Safebox

#0=ok; 1=warn; 2=crit
$OK = 0
$Warning = 1
$Critical = 2

c:\skript\curl.exe -s -k https://your-safebox.address:8443/netaccess/connstatus.html > C:\Skript\kv-safenet-state.log

if (Select-String -Quiet -Path c:\skript\kv-safenet-state.log -Pattern „You are logged in.“) {
  $status = $OK
  $statustext = „OK“
  $detail = „KV-Safenet Verbindnung OK“
}
else {
  $status = $CRITICAL
  $statustext = „CRITICAL“
  $detail = „KV-Safenet Verbindnung CRITICAL“
}

Write-Host „$status KV-Safenet – $($statustext) – $detail“

check_mk local Bash Script Auswertung SQLPlus DB-FULL Logfiles

#!/bin/bash
#
# Skript Logfiles auszuwerten
# speziell RMAN DB FULL Status
#
# Bsp. Format zur Analyse generiert mit SQLPlus
# ===== 09.06.2017 11:23:56 =====
#
# START_TIME END_TIME STATUS INPUT_TYPE INPUT_BYTE OUTPUT_BYT RANG
# ——————– ——————– ——————– ———- ———- ———- ———-
# 08.06.2017 23:00:04 08.06.2017 23:39:09 COMPLETED DB FULL 75.75G 12.36G 1
# 07.06.2017 23:00:04 07.06.2017 23:45:23 COMPLETED DB FULL 75.12G 12.10G 2
# 06.06.2017 23:00:03 06.06.2017 23:46:06 COMPLETED DB FULL 74.57G 11.88G 3
#
# ===== 16.06.2017 10:16:38 =====
#
# START_TIME END_TIME STATUS INPUT_TYPE INPUT_BYTE OUTPUT_BYT RANG
# ——————– ——————– ——————– ———- ———- ———- ———-
# 15.06.2017 23:00:06 15.06.2017 23:42:01 COMPLETED DB FULL 76.19G 12.46G 1
# 14.06.2017 23:00:06 14.06.2017 23:40:42 COMPLETED DB FULL 75.83G 12.38G 2
# 13.06.2017 23:00:04 13.06.2017 23:42:13 COMPLETED DB FULL 75.15G 12.14G 3
#
# End Comments
#

files=./datastore/rman/check_rman*.log

for file in $files
do

  service=`echo „$file“ | cut -d / -f4`
  linecount=`cat $file | awk ‚/\=\=\=\=\=/ {if (count) print count; print; count=0; next} {count++} END {print count}‘ | tail -n1`
  linecount_noheadline=$((linecount – 3))
  lastoutput=`tail -n $linecount_noheadline $file | sed ‚1!G;h;$!d‘ | tail -n1`
  enddate=`echo „$lastoutput“ | cut -d \ -f4`
  state_raw=`echo „$lastoutput“ | cut -d \ -f7`
  day=`echo „$enddate“ | cut -d \. -f1`
  month=`echo „$enddate“ | cut -d \. -f2`
  year=`echo „$enddate“ | cut -d \. -f3`
  date_normalized=`date -d $year-$month-$day +’%Y%m%d’`
  today=`date +’%Y%m%d’`

  if [ $today = $date_normalized ]
    then
      if [ $state_raw = „COMPLETED“ ]
      then
        echo „0 DB-FULL-$service – OK DB-FULL hat den Status COMPLETED! OK“
      elif [ $state_raw = „RUNNING“ ]
      then
        echo „1 DB-FULL-$service – WARN DB-FULL hat den Status RUNNING! WARN“
      elif [ $state_raw = „FAILED“ ]
      then
        echo „2 DB-FULL-$service – CRIT DB-FULL hat den Status FAILED! CRIT“
      fi
    else
    echo „2 DB-FULL-$service – CRIT DB-FULL Letzer Logeintrag zu alt! Logalter: $date_normalized State: $state_raw“
  fi

done

Comet P8541 Temperatur Sensor check_mk Skript

def inventory_temp1(info):
  inventory = []
  for descr in info:
    inventory.append ( ( None, None ) )
  return inventory

def check_temp1(item, params, info):
  temp1 = int(float(info[0][0]))
  perfdata = [ ( „temp“, info[0][0], 24, 25 ) ]
  if temp1 <= 25:
    return (0, „OK Temperature is below 25 – Actual %d“ % temp1, perfdata)
  else:
    return (2, „CRITICAL Temperature is above 25 – Actual %d“ % temp1, perfdata)

check_info[„temp1“] = {
  ‚check_function‘ : check_temp1,
  ‚inventory_function‘ : inventory_temp1,
  ’service_description‘ : ‚Temperatur 1‘,
  ‚has_perfdata‘ : True,
  „snmp_info“ : ( „.1.3.6.1.4.1.22626.1.5.2.1.2“, [„0“]),
}

Simple Powershell MegaRAID Logical Drive State Skript for cmk

Ein ganz einfaches Skript, um den State des Logical Drives mit MegaCLI und als local Check von CMK zu monitoren:

$OK = 0
#$Warning = 1
$Critical = 2
$RaidState = $(C:\Progra~2\MegaRAID\MegaCli.exe -LDInfo -l0 -aALL)
if ($RaidState[9] -eq „State               : Optimal“) {
  $status = $OK
  $statustext = „OK“
  $detail = „RAID Status des Logical Drives 0 OK“
else {
  $status = $Critical
  $statustext = „CRITICAL“
  $detail = „RAID Status des Logical Drives 0 CRITICAL“
}
Write-Host „$status RaidState0 – $($statustext): $detail“

Simple Bash MegaRAID Logical Drive State Skript for cmk

Ein ganz einfaches Skript, um den State des Logical Drives mit MegaCLI und als local Check von CMK zu monitoren:

state=`/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -lALL -aALL | grep State | cut -d \  -f17`  if [ $state = "Optimal" ] then   echo "0 LDState - OK LogicalDrive Status OK" else   echo "2 LDState - CRITICAL LogicalDrive Status CRIT" fi

Eventhandler und Script zum Restart von Services

1. Skript

OMD[site]:~/version/lib/nagios/plugins/eventhandler$ cat restart_win_spooler.sh
#!/bin/sh
#
# Eventhandler-Script für den Restart von Services
case „$1“ in
OK)
        # Service OK – nichts tun
        ;;
WARNING)
        # Service WARNUNG – nichts tun
        ;;
UNKNOWN)
        # Service UNKNOW – nichts tun
        ;;
CRITICAL)
        # SOFT oder HARD
        case „$2“ in
        # Ist SOFT warten bis Core in HARD wechselt
        SOFT)
                # Warten…
                case „$3“ in
                # Dreimal warten
                1)
                        echo -n „Restart des Spooler-Service (dritter kritischer „Soft“-Zustand)…“
                        # Aufrufen des Init-Scripts, um zu restarten
                        /usr/bin/winexe -U DOMAIN/User%’Password‘ //$4 ’net start Spooler‘
                        ;;
                        esac
                ;;
        # HARD-State
        HARD)
                echo -n „Restart des Spooler-Service…“
                # Aufrufen des Init-Scripts, um zu restarten
                /usr/bin/winexe -U DOMAIN/User%’Password‘ //$4 ’net start Spooler‘
                ;;
        esac
        ;;
esac
exit 0

RRDTool Filesystem Trend Hochrechnungen

Genutzte Umgebung:
Open Monitoring Distribution 1.20

Ergänzungen:
RRD
PECL
etc.
Leider kann ich aus Erinnerung nicht mehr wiedergeben, wie die Installation der Pakete erfolgte.
Entsprechend versuchen für die eingesetzte Distribution Pakete zu bekommen.
Es wurden auch teilweise -devel Pakete genutzt.

Gute Einstiegspunkte sind Google und ein Artikel im Internet:
Quelle: http://tiskanto.blogspot.de/2011/12/trend-predictions-with-rrd-tool-not-so.html

Nach Erfüllen der Voraussetzungen können Graphen generiert werden.
Da es für mich sehr kompliziert war die RRD-Parameter zu definieren, dokumentiere ich sie im folgenden.
Pfade müssen auf die individuelle eigene Installation abgeändert werden:

#!/bin/sh
/path-to-rrdtool/rrdtool graph fs-server1.png \
–imgformat=PNG \
–start=-12w \
–end=’+25w‘ \
–title=“Filesystem Server1″ \
–font TITLE:12: \
–units-exponent=0 \
–vertical-label=“Filesystem“ \
–height=450 \
–width=800 \
–upper-limit 1500000 \
–lower-limit 0 \
DEF:a=“/omd/sites/mainsite/var/pnp4nagios/perfdata/server1/fs_C___C__.rrd“:1:AVERAGE:step=300 \
CDEF:idle=a,0.00,EQ,INF,0,IF \
VDEF:avg=a,AVERAGE \
VDEF:slope=a,LSLSLOPE \
VDEF:cons=a,LSLINT \
CDEF:lsl2=a,POP,slope,COUNT,*,cons,+ \
CDEF:pred=lsl2,2000000,2048000,LIMIT \
VDEF:minpred=pred,FIRST \
VDEF:maxpred=pred,LAST \
GPRINT:a:AVERAGE:“Filesystem Avg\: %8.0lf“ \
AREA:a#00B2EE:“Usage“ \
AREA:idle#AFEEEE \
AREA:pred#BCD2EE \
LINE3:lsl2#ff0000:“Least Sqr Pred.\n“:dashes=8 \
LINE4:2048000#000000:“Full.\n“ \
AREA:5#FF000022::STACK \
AREA:5#FF000044::STACK \
GPRINT:minpred:“reaching 2000000 on \: %c\n“:strftime \
GPRINT:maxpred:“reaching 2048000 on \: %c\n“:strftime \

„RRDTool Filesystem Trend Hochrechnungen“ weiterlesen