Test VBScript retourne UNKNOWN:--

Résolu/Fermé
F.S88 Messages postés 6 Date d'inscription jeudi 13 avril 2017 Statut Membre Dernière intervention 14 avril 2017 - 13 avril 2017 à 10:49
 F.S88 - 18 avril 2017 à 09:19
Bonjour,

J'ai un nagios 4.1 installé sous centos 6.8 et sur la machine distante j'ai nsclient 0.5 d'installé

je dois mettre en place une vérification de taille d'un dossier sur une machine windows 7, je veux utilisé le script vbs suivant
https://exchange.nagios.org/directory/Plugins/Operating-Systems/Windows-NRPE/check_folder_size-2Evbs/details

Du coup j'ai le télécharger et je le copier sur la machine windows où est installé le nsclient (C:\Program Files\NSClient++\scripts)

J'ai tester d'abord le script en local depuis l'invite de commandes
c:\Programm Files\NSClient++>scripts\check_folder_size.vbs

j'ai le résultat suivant : https://drive.google.com/file/d/0B3rPpOA9V6hldUhkc0VUc1VTOFk/view?usp=sharing
et le "echo %ERRORLEVEL%" me retourne 0

Doit-je modifier le script pour ajouter l'emplacement du dossier à supervisé ? si oui comment ?
Je tient à préciser que je n'y connais pas grand chose en VBScript

Merci de votre aide
A voir également:

4 réponses

jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
Modifié le 13 avril 2017 à 11:08
Bonjour,

Donc le script utilisé est celui-ci (c'est mieux de le mettre sur le forum plutot que d'en mettre un lien...)
Dim strfolder
Dim intwarning
Dim intcritic
Dim wsh
Dim intvelkost
Dim intjednotka
Dim Perf_Data
'##########################################################'
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("WScript.Shell")
'##########################################################'
If Wscript.Arguments.Count = 3 Then
strfolder = Wscript.Arguments(0)
intwarning = Wscript.Arguments(1)
intcritic = Wscript.Arguments(2)

Set objFolder = objFSO.GetFolder(strfolder)
intjednotka = 1048576 '1MB->bytes'
intvelkost = objFolder.Size/intjednotka
Perf_Data = "|'FolderSize'=" & round (objFolder.Size / 1048576,1) & "MB;"


if (objFolder.Size/1024000) > Cint(intcritic) then
Wscript.Echo "CRITICAL:" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
Wscript.Quit(2)
elseif (objFolder.Size/1048576) > Cint(intwarning) then
Wscript.Echo "WARNING:" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
Wscript.Quit(1)
else
Wscript.Echo "OK:" & round (objFolder.Size /1048576,1) & " MB" & Perf_Data
Wscript.Quit(0)
end if

else
Wscript.Echo "UNKNOWN:"& strfolder &"-" & intwarning & "-" & intcritic
Wscript.Quit(3)
End If 



Ce script attend 3 arguments ... les as tu passé ?
strfolder = Wscript.Arguments(0)
intwarning = Wscript.Arguments(1)
intcritic = Wscript.Arguments(2)


Le premier ... strfolder .. est le chemin du répertoire à scanner

Au cas où... pour rappel.... pour passer des arguments :
il suffit de les placer à la suite de ton fichier lors de son appel......
tonfichier.vbs "c:\temp\"  "90"  "50"



Sinon si tu veux... tu remplaces les arguments par des valeurs en dur dans le code
strfolder = "c:\temp\"



Cordialement, 
Jordane                                                                 
0
F.S88 Messages postés 6 Date d'inscription jeudi 13 avril 2017 Statut Membre Dernière intervention 14 avril 2017
13 avril 2017 à 11:58
Salut Jordan merci de ta réponse rapide

Déjà j'avais pas passé les arguments parce que je ne savais qu'il fallait le faire.
Maintenant j'aimerais passé les arguments suivant :
check_folder_size.vbs "C:\Nom\Dossier" "70" "50"


Mais je ne sais pas où les placer exactement dans script. J'ai essayer de les mettre à différent endroit mais à chaque fois j'ai une erreur


J'ai placer les arguments en dur dans le code en mettant
strfolder = "C:\Test\WinNT" "60" "40"

j'ai le même message d'erreur

Ligne 31, Caract. 29 correspondent aux arguments
 intwarning
et
intcritic
.
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
13 avril 2017 à 12:02
Je t'ai dit qu'il y a 3 arguments
Donc 3 variables différentes
strfolder = Wscript.Arguments(0)
intwarning = Wscript.Arguments(1)
intcritic = Wscript.Arguments(2)

Pour les mettre en dur dans le code ... il faut les mettre dans ces 3 variables !

strfolder = "C:\Test\WinNT"
intwarning = 60
intcritic = 40
0
F.S88 Messages postés 6 Date d'inscription jeudi 13 avril 2017 Statut Membre Dernière intervention 14 avril 2017
13 avril 2017 à 12:16
J'ai ajouter les arguments en dur dans les 3 variables
strfolder = "C:\Test\WinNT"
intwarning = 60
intcritic = 40


j'ai la 1er erreur
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
Modifié le 13 avril 2017 à 12:59
Oui..

Faut virer le premier if
(Et le else qui va avec bien entendu )

Dim strfolder
Dim intwarning
Dim intcritic
Dim wsh
Dim intvelkost
Dim intjednotka
Dim Perf_Data
'##########################################################'
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("WScript.Shell")
'##########################################################'
strfolder = "C:\Test\WinNT"
intwarning = 60
intcritic = 40

Set objFolder = objFSO.GetFolder(strfolder)
intjednotka = 1048576 '1MB->bytes'
intvelkost = objFolder.Size/intjednotka
Perf_Data = "|'FolderSize'=" & round (objFolder.Size / 1048576,1) & "MB;"


if (objFolder.Size/1024000) > Cint(intcritic) then
    Wscript.Echo "CRITICAL:" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
     Wscript.Quit(2)
elseif (objFolder.Size/1048576) > Cint(intwarning) then
    Wscript.Echo "WARNING:" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
    Wscript.Quit(1)
else
    Wscript.Echo "OK:" & round (objFolder.Size /1048576,1) & " MB" & Perf_Data
    Wscript.Quit(0)
end if
0
F.S88 Messages postés 6 Date d'inscription jeudi 13 avril 2017 Statut Membre Dernière intervention 14 avril 2017
13 avril 2017 à 14:25
Merci encore Jordane, ça marche nickel. Maintenant j'ai le message qui affiche la taille du dossier.


Une dernière question svp
Si je veux supervisé plusieurs dossiers qui se situe sur la même machine et dans le même répertoire, pense-tu que ce possible d'utiliser un seul script ou il faut un script par dossier ?
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
13 avril 2017 à 15:11
Ben c'était le principe d'origine ... avec le passage de paramètres lors de l'appel au script.
0
F.S88 Messages postés 6 Date d'inscription jeudi 13 avril 2017 Statut Membre Dernière intervention 14 avril 2017 > jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024
13 avril 2017 à 16:24
j'ai repris le script d'origine et j'ai rajouter le code ci-dessous mais je ne sais si je le placé au bon endroit
check_folder_size.vbs "C:\Test\WinNT" "50" "60"


Script d'origine
Dim strfolder
Dim intwarning
Dim intcritic
Dim wsh
Dim intvelkost
Dim intjednotka
Dim Perf_Data

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("WScript.Shell")

check_folder_size.vbs "C:\Test\WinNT" "50" "60"

If Wscript.Arguments.Count = 3 Then
strfolder = Wscript.Arguments(0)
intwarning = Wscript.Arguments(1)
intcritic = Wscript.Arguments(2)

Set objFolder = objFSO.GetFolder(strfolder)
intjednotka = 1048576 '1MB->bytes'
intvelkost = objFolder.Size/intjednotka
Perf_Data = "|'FolderSize'=" & round (objFolder.Size / 1048576,1) & "MB;"

if (objFolder.Size/1048576) > Cint(intwarning) then 
Wscript.Echo "WARNING:" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
Wscript.Quit(1)
elseif (objFolder.Size/1024000) > Cint(intcritic) then 
Wscript.Echo "CRITICAL:" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
Wscript.Quit(2)
else
Wscript.Echo "OK:" & round (objFolder.Size /1048576,1) & " MB" & Perf_Data
Wscript.Quit(0)
end if

else
Wscript.Echo "UNKNOWN:"& strfolder &"-" & intwarning & "-" & intcritic
Wscript.Quit(3)
End If
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650 > F.S88 Messages postés 6 Date d'inscription jeudi 13 avril 2017 Statut Membre Dernière intervention 14 avril 2017
Modifié le 13 avril 2017 à 16:55
reflechi deux minutes ......
Tu ne peux pas appeler le script ... à l'intérieur du script lui même.....

Tu dois avoir :
1 fichier (nommé check_folder_size.vbs ) qui contient le script actuel
1 fichier qui fera les différents appels au script check_folder_size.vbs

Un truc du genre :
Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")

objShell.Run "check_folder_size.vbs C:\Test\WinNT 50 60 " 
objShell.Run "check_folder_size.vbs C:\autre\dossier 50 60 " 
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
13 avril 2017 à 19:35
Finalement ... le plus simple c'est de transformer le script en "fonction"

Voici un exemple :

function bigbrotherFolder(strfolder,intwarning,intcritic)

Dim wsh
Dim intvelkost
Dim intjednotka
Dim Perf_Data
Dim result
'##########################################################'
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("WScript.Shell")
'##########################################################'

Set objFolder = objFSO.GetFolder(strfolder)
intjednotka = 1048576 '1MB->bytes'
intvelkost = objFolder.Size/intjednotka
Perf_Data = "|'FolderSize'=" & round (objFolder.Size / 1048576,1) & "MB;"


if (objFolder.Size/1024000) > Cint(intcritic) then
    result = "CRITICAL - " & strfolder & ":" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
 elseif (objFolder.Size/1048576) > Cint(intwarning) then
    result =  "WARNING - " & strfolder & ":" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
else
    result = "OK - " & strfolder & ":" & round (objFolder.Size /1048576,1) & " MB" & Perf_Data
end if

 bigbrotherFolder = result
end function


'-----------------------------------------------------------------------------'
' Exemple d'utilisation
'------------------------------------------------------------------------------'
'Debut du programme:


'premier rep
var = bigbrotherFolder("C:\__Jordane__\TEMP",40,60)
msgbox var

'second rep
var = bigbrotherFolder("C:\__Jordane__\DOCUMENTS",50,60) 
msgbox var

    
0
F.S88 Messages postés 6 Date d'inscription jeudi 13 avril 2017 Statut Membre Dernière intervention 14 avril 2017 > jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024
14 avril 2017 à 11:19
La transformation du script en function permet de faire exactement ce que je veux et il fonctionne en local mais dès que je l'exécute sur nagios j'ai
"CHECK_NRPE: Socket timeout after 10 seconds."

C'est ne pas un problème nrpe puisque j'ai d'autres services qui utilise le service nrpe
0