NSClient++ : gestion des serveurs Windows depuis Nagios
Posté : ven. avr. 08, 2016 3:12 pm
par Bidouille
Le couple Nagios/NSClient++ est indéniablement très pratique dans la surveillance de serveurs sous Windows.
Une fois installé le service NRPE, vous avez tout loisir pour interroger la place disque, l'utilisation de la mémoire ou du processus.
Mais un des trucs les plus énervants sous Windows, c'est le passage du mercredi et de son lot de rustines.
Le service Windows Update se lance et collecte les mises à jour système.
Il est donc primordiale de surveiller également ce processus et savoir si un serveur demande à redémarrer.
Partie NSClient++
Posté : mar. avr. 19, 2016 1:06 pm
par Bidouille
Téléchargez l'outil depuis le site NSClient.org :
http://nsclient.org/download/A ce jour, j'utilise la 0.4.4.
Ce dernier s'installe comme n'importe quel logiciel.
Structure minimale du
nsclient.ini :
Code : Tout sélectionner
[/modules]
CheckDisk = 1
CheckEventLog = 1
CheckExternalScripts = 1
CheckHelpers = 1
CheckNSCP = 1
CheckSystem = 1
NRPEServer = 1
NSClientServer = 1
[/settings/default]
allowed hosts = 10.0.0.0/8
password = xxxxxxx
[/settings/NRPE/server]
verify mode = none
insecure = true
use ssl = 0
allow nasty characters = 1
allow arguments = 1
port = 5666
extended response = 0
[/settings/external scripts]
allow arguments=true
[/settings/external scripts/wrappings]
wsf=cscript //nologo %SCRIPT%
[/settings/external scripts/wrapped scripts]
verif_maj_win=scripts\verif_maj_win.wsf
NB : nos serveurs étant dans un domaine privé, SSL n'est pas activé.
Partie script
Posté : mar. avr. 19, 2016 2:15 pm
par Bidouille
Pour savoir si Windows Update propose des mises à jour ou demande à redémarrer, j'ai opté pour un script WSF.
Code : Tout sélectionner
<job>
<script language="VBScript">
Set objShell = CreateObject("WScript.Shell")
Dim sysroot
sysroot = objShell.ExpandEnvironmentStrings("%systemroot%")
Set objExec = objShell.Exec("cmd.exe /c type " & sysroot & "\SoftwareDistribution\ReportingEvents.log")
results = LCase(objExec.StdOut.ReadAll)
res_split = Split(results, vbCrLf)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = "(.)\S*\s*\S*\s*\S*\s*\d\s*(\d*)\s*\S*\s*\S*[0-9\s]*\S*\s*\S*\s*.*\t(.*)"
regEx.IgnoreCase = true
count = 1
ReDim arrDyn(1)
For Each elem in res_split
firstsign = regEx.Replace(elem, "$1")
If (firstsign = "{") Then
number = regEx.Replace(elem, "$2")
finish = regEx.Replace(elem, "$3")
If (number = 147) Then
count = count + 1
ReDim Preserve arrDyn(count + 1)
arrDyn(count + 1) = finish
End If
End If
Next
mount_updates = -1
For x = 0 to UBound(arrDyn)
If x = UBound(arrDyn) Then
end_array = Split(arrDyn(x), " ")
mount_updates = end_array(UBound(end_array) - 1)
End If
Next
Set objSysInfo = CreateObject("Microsoft.Update.SystemInfo")
If objSysInfo.RebootRequired Then
Wscript.echo("Reboot required!")
status = 2
Else
If mount_updates > 0 Then
If mount_updates = 1 Then
Wscript.echo("Warning: 1 Update detected!")
status = 1
ElseIf mount_updates >= 2 Then
Wscript.echo("Critical: " & mount_updates & " Updates detected!")
status = 2
End If
Else
Wscript.echo("OK, no updates detected!")
End If
End If
Wscript.Quit(status)
</script>
</job>
Nommez ce fichier
verif_maj_win.wsf et copiez le dans le répertoire
script/ de NSClient++
Partie Nagios
Posté : mar. avr. 19, 2016 3:25 pm
par Bidouille
Il suffit de créer une commande check_nrpe et de passer le nom du script :
Code : Tout sélectionner
root@nagios:/usr/local/nagios/libexec# ./check_nrpe -H 10.0.0.56 -c verif_maj_win
nagios1.png