Munin

From Tuxunix
Jump to: navigation, search

Plugins personnalisé Windows

  • Fichier bat : Windows_Memory.cmd
@echo off
call %windir%\system32\cscript.exe //NoLogo "C:\XXXXX\MUNIN\plugins\Windows_Memory.vbs" %1
  • Fichier VBS : Windows_Memory.vbs
set args = WScript.Arguments
num = args.Count
if num = 0 then
    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("select * from Win32_PerfRawData_PerfOS_Memory")
    For Each objItem in colItems
         mem_free=int(objItem.AvailableBytes)
    Next

end if
if num = 0 then
    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("select * from CIM_PhysicalMemory")     
    For Each objItem in colItems
         mem_install=mem_install + int(objItem.Capacity)
    Next
         Wscript.StdOut.Write "mem2.value " & mem_install & Vblf
         mem_used=mem_install - mem_free
         Wscript.StdOut.Write "mem3.value " & mem_used & Vblf
         Wscript.StdOut.Write 	"." & Vblf
end if
if num = 1 then
    if args.Item(0) = "config" then
         WScript.StdOut.Write "graph_title Memory usage" & Vblf
         WScript.StdOut.Write "graph_category System" & Vblf
    WScript.StdOut.Write "graph_vlabel Bytes" & Vblf
    WScript.StdOut.Write "graph_args --base 1024 -l 0" & Vblf
    WScript.StdOut.Write "mem2.label Memoire disponible" & Vblf
    WScript.StdOut.Write "mem2.type GAUGE" & Vblf
    WScript.StdOut.Write "mem2.draw LINE2" & Vblf
    WScript.StdOut.Write "mem3.label Memoire utilisee" & Vblf
    WScript.StdOut.Write "mem3.type GAUGE" & Vblf
    WScript.StdOut.Write "mem3.draw AREA" & Vblf &"." & Vblf

    elseif args.Item(0) = "name" then
         WScript.StdOut.Write("memory")
    end if
end if
  • Puis dans le fichier ini : "munin-node.ini"
Check0x01=C:\XXXXX\MUNIN\plugins\Windows_Memory.cmd


Envoyer alerte Munin vers Icinga ( Munin alert send to Icinga or Nagios)

  • Configuration Munin (/etc/munin/munin.conf) :

Add this line

contact.nagios.command [ ! -e /tmp/muninTestIcinga2.txt ] && mkfifo -m 666 /tmp/muninTestIcinga2.txt ; echo "[${var:group};${var:host}] -> \
${var:graph_title} -> warnings: ${loop<,>:wfields ${var:label}=${var:value}},criticals: ${loop<,>:cfields ${var:label}=${var:value}}">> /tmp/muninTestIcinga2.txt


  • Plugin Nagios :
#!/bin/bash

#
#@Name          check_gen_munin.sh
#@Fonction      check alert munin send
#@Depends       no depends !
#@Version       0.1
#@Authors       SYSTEM DYNAMICS
#@Modify by     XXXX
#

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
fileDir="/tmp/muninTestIcinga2.txt"
[ ! -e /tmp/muninTestIcinga2.txt ] && mkfifo -m 666 /tmp/muninTestIcinga2.txt


DATA=""
STATE=$STATE_OK
while read -t 1 LINE; do
       DATA="$DATA$LINE"
       if [ $STATE == $STATE_CRITICAL ]; then
               continue;
       fi
       w=$(echo "$LINE" | grep -Po "(?<=warnings: ).*(?=,)")
       c=$(echo "$LINE" | grep -Po "(?<=criticals: ).*$")
       if [ ! -z "$w" ]; then
               STATE=$STATE_WARNING
       fi
       if [ ! -z "$c" ]; then
               STATE=$STATE_CRITICAL
       fi
done <> $fileDir

if [ -z "$DATA" ]; then
       echo .OK.
       exit 0
else
       echo "$DATA"
       exit $STATE
fi