update
This commit is contained in:
230
bibliotheque/files/nsclient/scripts/op5/check_ad.vbs
Normal file
230
bibliotheque/files/nsclient/scripts/op5/check_ad.vbs
Normal file
@ -0,0 +1,230 @@
|
||||
'Script to check the status of a DOMAIN controller and report to Nagios
|
||||
'requires DCDIAG.EXE
|
||||
'Author: Felipe Ferreira
|
||||
'Version: 3.0
|
||||
'
|
||||
'Mauled over by John Jore, j-o-h-n-a-t-j-o-r-e-d-o-t-n-o 16/11/2010 to work on W2K8, x32
|
||||
'as well as remove some, eh... un-needed lines of code, general optimization as well as adding command parameter support
|
||||
'This is where i found the original script, http://felipeferreira.net/?p=315&cpage=1#comments
|
||||
'Tested by JJ on W2K8 SP2, x86
|
||||
' W2K3 R2 SP2, x64
|
||||
'Version 3.0-JJ-V0.2
|
||||
'Todo: Proper error handling
|
||||
' Add /help parameter
|
||||
' Add support for the two tests which require additional input (dcpromo is one such test)
|
||||
'Version 3.0-JJ-V0.3
|
||||
' Removed some surplus language detection code
|
||||
' Including non-working English test on a W2K8 x32 DC
|
||||
' Added support for multi-partition checks like 'crossrefvalidation'. Previously the last status result would mask previous failures
|
||||
' Incorporated Jonathan Vogt's german and multiline tests
|
||||
|
||||
|
||||
'Force all variables to be declared before usage
|
||||
option explicit
|
||||
|
||||
'Array for name and status (Ugly, but redim only works on last dimension, and can't set initial size if redim
|
||||
dim name(), status()
|
||||
redim preserve name(0)
|
||||
redim preserve status(0)
|
||||
redim preserve lock(0)
|
||||
|
||||
'Debug switch
|
||||
dim verbose : verbose = 0
|
||||
|
||||
'Return variables for NAGIOS
|
||||
const intOK = 0
|
||||
const intWarning = 1 'Not used. What dcdiag test would be warning instead of critical?
|
||||
const intCritical = 2
|
||||
const intUnknown = 3
|
||||
|
||||
'Lang dependend. Default is english
|
||||
dim strOK : strOK = "passed"
|
||||
dim strNotOK : strNotOk = "failed"
|
||||
|
||||
'Call dcdiag and grab relevant output
|
||||
exec(cmd)
|
||||
|
||||
'Generate NAGIOS compatible output from dcdiag
|
||||
printout()
|
||||
|
||||
'call dcdiag and parse the output
|
||||
sub exec(strCmd)
|
||||
'Declare variables
|
||||
dim objShell : Set objShell = WScript.CreateObject("WScript.Shell")
|
||||
dim objExecObject, lineout, tmpline
|
||||
lineout = ""
|
||||
'Command line options we're using
|
||||
pt strCmd
|
||||
|
||||
Set objExecObject = objShell.Exec(strCmd)
|
||||
'Loop until end of output from dcdiag
|
||||
do While not objExecObject.StdOut.AtEndOfStream
|
||||
tmpline = lcase(objExecObject.StdOut.ReadLine())
|
||||
|
||||
'Check the version of DCDiag being used and change the global 'passed' / 'failed' strings
|
||||
call DetectLang(tmpline)
|
||||
|
||||
if (instr(tmpline, ".....")) then
|
||||
'testresults start with a couple of dots, reset the lineout buffer
|
||||
lineout= tmpline
|
||||
'pt "lineout buffer '" & lineout & "'"
|
||||
else
|
||||
'Else append the next line to the buffer to capture multiline responses
|
||||
lineout = lineout + tmpline
|
||||
'pt "lineout buffer appended '" & lineout & "'"
|
||||
end if
|
||||
|
||||
if instr(lineout, lcase(strOK)) then
|
||||
'we have a strOK String which means we have reached the end of a result output (maybe on newline)
|
||||
call parse(lineout)
|
||||
lineout = ""
|
||||
end if
|
||||
loop
|
||||
|
||||
'Why call this at the end? Is it not pointless as we've looped through the entire output from dcdiag in the above loop?!?
|
||||
'call parse(lineout)
|
||||
end sub
|
||||
|
||||
|
||||
sub DetectLang(txtp)
|
||||
|
||||
'Change from looking for English words if we find the string below:
|
||||
if (instr(lcase(txtp), lcase("Verzeichnisserverdiagnose"))) then 'German
|
||||
pt "Detected German Language, changing the global test strings to look for"
|
||||
strOK = "bestanden"
|
||||
strNotOk = "nicht bestanden"
|
||||
end if
|
||||
|
||||
end sub
|
||||
|
||||
|
||||
sub parse(txtp)
|
||||
'Parse output of dcdiag command and change state of checks
|
||||
dim loop1
|
||||
|
||||
'Is this really required? Or is it for pretty debug output only?
|
||||
txtp = Replace(txtp,chr(10),"") ' Newline
|
||||
txtp = Replace(txtp,chr(13),"") ' CR
|
||||
txtp = Replace(txtp,chr(9),"") ' Tab
|
||||
do while instr(txtp, " ")
|
||||
txtp = Replace(txtp," "," ") ' Some tidy up
|
||||
loop
|
||||
|
||||
' We have to test twice because some localized (e.g. German) outputs simply use 'not', or 'nicht' as a prefix instead of 'passed' / 'failed'
|
||||
if instr(lcase(txtp), lcase(strOK)) then
|
||||
'What are we testing for now?
|
||||
pt "Checking :" & txtp & "' as it contains '" & strOK & "'"
|
||||
'What services are ok? 'By using instr we don't need to strip down text, remove vbCr, VbLf, or get the hostname
|
||||
for loop1 = 0 to Ubound(name)-1
|
||||
if (instr(lcase(txtp), lcase(name(loop1)))) AND (lock(loop1) = FALSE) then
|
||||
status(loop1)="OK"
|
||||
pt "Set the status for test '" & name(loop1) & "' to '" & status(loop1) & "'"
|
||||
end if
|
||||
next
|
||||
end if
|
||||
|
||||
' if we find the strNotOK string then reset to CRITICAL
|
||||
if instr(lcase(txtp), lcase(strNotOK)) then
|
||||
'What are we testing for now?
|
||||
pt txtp
|
||||
for loop1 = 0 to Ubound(name)-1
|
||||
if (instr(lcase(txtp), lcase(name(loop1)))) then
|
||||
status(loop1)="CRITICAL"
|
||||
'Lock the variable so it can't be reset back to success. Required for multi-partition tests like 'crossrefvalidation'
|
||||
lock(loop1)=TRUE
|
||||
pt "Reset the status for test '" & name(loop1) & "' to '" & status(loop1) & "' with a lock '" & lock(loop1) & "'"
|
||||
end if
|
||||
next
|
||||
end if
|
||||
end sub
|
||||
|
||||
'outputs result for NAGIOS
|
||||
sub printout()
|
||||
dim loop1, msg : msg = ""
|
||||
|
||||
for loop1 = 0 to ubound(name)-1
|
||||
msg = msg & name(loop1) & ": " & status(loop1) & ". "
|
||||
next
|
||||
|
||||
'What state are we in? Show and then quit with NAGIOS compatible exit code
|
||||
if instr(msg,"CRITICAL") then
|
||||
wscript.echo "CRITICAL - " & msg
|
||||
wscript.quit(intCritical)
|
||||
else
|
||||
wscript.echo "OK - " & msg
|
||||
wscript.quit(intOK)
|
||||
end if
|
||||
end sub
|
||||
|
||||
'Print messages to screen for debug purposes
|
||||
sub pt(msgTxt)
|
||||
if verbose then
|
||||
wscript.echo msgTXT
|
||||
end if
|
||||
end sub
|
||||
|
||||
'What tests do we run?
|
||||
function cmd()
|
||||
dim loop1, test, tests
|
||||
const intDefaultTests = 6
|
||||
|
||||
cmd = "dcdiag " 'Start with this
|
||||
|
||||
'If no command line parameters, then go with these defaults
|
||||
if Wscript.Arguments.Count = 0 Then
|
||||
redim preserve name(intDefaultTests)
|
||||
redim preserve status(intDefaultTests)
|
||||
redim preserve lock(intDefaultTests)
|
||||
'Test name
|
||||
name(0) = "services"
|
||||
name(1) = "replications"
|
||||
name(2) = "advertising"
|
||||
name(3) = "fsmocheck"
|
||||
name(4) = "ridmanager"
|
||||
name(5) = "machineaccount"
|
||||
|
||||
'Set default status for each named test
|
||||
for loop1 = 0 to (ubound(name)-1)
|
||||
status(loop1) = "CRITICAL"
|
||||
lock(loop1) = FALSE
|
||||
cmd = cmd & "/test:" & name(loop1) & " "
|
||||
next
|
||||
else
|
||||
'User specified which tests to perform.
|
||||
|
||||
for loop1 = 0 to wscript.arguments.count - 1
|
||||
if (instr(lcase(wscript.Arguments(loop1)), lcase("/test"))) then
|
||||
|
||||
'If parameter is wrong, give some hints
|
||||
if len(wscript.arguments(loop1)) < 6 then
|
||||
wscript.echo "Unknown parameter. Provide name of tests to perform like this:"
|
||||
wscript.echo vbTAB & "'cscript //nologo " & Wscript.ScriptName & " /test:advertising,dfsevent'"
|
||||
wscript.quit(intUnknown)
|
||||
end if
|
||||
|
||||
'Strip down the test to individual items
|
||||
tests = right(wscript.arguments(loop1), len(wscript.arguments(loop1))-6)
|
||||
pt "Tests: '" & tests & "'"
|
||||
|
||||
tests = split(tests,",")
|
||||
for each test in tests
|
||||
cmd = cmd & " /test:" & test
|
||||
|
||||
'Expand the array to make room for one more test
|
||||
redim preserve name(ubound(name)+1)
|
||||
redim preserve status(ubound(status)+1)
|
||||
redim preserve lock(ubound(lock)+1)
|
||||
|
||||
'Store name of test and status
|
||||
name(Ubound(name)-1) = test
|
||||
status(Ubound(status)-1) = "CRITICAL" 'Default status. Change to OK if test is ok
|
||||
lock(Ubound(lock)-1) = FALSE 'Don't lock the variable yet.
|
||||
|
||||
'pt "Contents: " & name(Ubound(name)-1) & " " & status(Ubound(status)-1)
|
||||
next
|
||||
end if
|
||||
next
|
||||
end if
|
||||
'We end up with this to test:
|
||||
pt "Command to run: " & cmd
|
||||
end function
|
101
bibliotheque/files/nsclient/scripts/op5/check_time.vbs
Normal file
101
bibliotheque/files/nsclient/scripts/op5/check_time.vbs
Normal file
@ -0,0 +1,101 @@
|
||||
' Author: Mattias Ryrl<72>n (mr@op5.com)
|
||||
' Website: http://www.op5.com
|
||||
' Created: 2008-09-18
|
||||
' Updated: 2008-10-09
|
||||
' Version: 0.9.1
|
||||
' Description: Check the offset of your server vs your Active Directory Domain.
|
||||
'
|
||||
' Usage cscript /NoLogo check_ad_time.vbs <domain> "<offset>"
|
||||
'
|
||||
' Changelog:
|
||||
'
|
||||
' 0.9.1:
|
||||
' * Fixed timeformat (i think, needs feedback).
|
||||
' * Changed /domain to /computers, still works to use the AD domain. eg domain.com
|
||||
'
|
||||
' 0.9:
|
||||
' Initial Release
|
||||
'
|
||||
|
||||
Err = 3
|
||||
msg = "UNKNOWN"
|
||||
|
||||
Set Args = WScript.Arguments
|
||||
If WScript.Arguments.Count <= 1 Then
|
||||
Usage()
|
||||
Else
|
||||
domain = Args.Item(0)
|
||||
|
||||
offset = Args.Item(1)
|
||||
|
||||
offset = Replace(offset,",",".")
|
||||
|
||||
Set objShell = CreateObject("Wscript.Shell")
|
||||
strCommand = "C:\windows\system32\w32tm.exe /monitor /computers:" & domain
|
||||
set objProc = objShell.Exec(strCommand)
|
||||
|
||||
input = ""
|
||||
strOutput = ""
|
||||
|
||||
Do While Not objProc.StdOut.AtEndOfStream
|
||||
input = objProc.StdOut.ReadLine
|
||||
|
||||
If InStr(input, "NTP") Then
|
||||
strOutput = input
|
||||
End If
|
||||
Loop
|
||||
|
||||
Set myRegExp = New RegExp
|
||||
myRegExp.IgnoreCase = True
|
||||
myRegExp.Global = True
|
||||
myRegExp.Pattern = " NTP: ([+-]+)([0-9]+).([0-9]+)s offset"
|
||||
|
||||
Set myMatches = myRegExp.Execute(strOutput)
|
||||
|
||||
result = ""
|
||||
dir = ""
|
||||
|
||||
For Each myMatch in myMatches
|
||||
If myMatch.SubMatches.Count > 0 Then
|
||||
For I = 0 To myMatch.SubMatches.Count - 1
|
||||
If I = 0 Then
|
||||
dir = myMatch.SubMatches(I)
|
||||
ElseIf I > 1 Then
|
||||
result = result & "." & myMatch.SubMatches(I)
|
||||
Else
|
||||
result = result & myMatch.SubMatches(I)
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
|
||||
If Left(dir, 1) = "-" Then
|
||||
result = CDbl(result)
|
||||
Else
|
||||
result = CDbl("-" & result)
|
||||
End If
|
||||
|
||||
If result > CDbl(offset) OR result < -CDbl(offset) Then
|
||||
Err = 2
|
||||
msg = "NTP CRITICAL: Offset " & result & " secs|offset: " & result & ";0;" & Replace(CDbl(offset),",",".") & ";"
|
||||
Else
|
||||
Err = 0
|
||||
msg = "NTP OK: Offset " & result & " secs|offset: " & result & ";0;" & Replace(CDbl(offset),",",".") & ";"
|
||||
End If
|
||||
End If
|
||||
|
||||
Wscript.Echo msg
|
||||
Wscript.Quit(Err)
|
||||
|
||||
Function Usage()
|
||||
Err = 3
|
||||
WScript.Echo "Usage cscript /NoLogo check_ad_time.vbs <domain> ""<offset>"""
|
||||
Wscript.Echo ""
|
||||
Wscript.Echo "domain Name of domain to check roles on"
|
||||
Wscript.Echo ""
|
||||
Wscript.Echo "offset total number of seconds offset allowed."
|
||||
Wscript.Echo " will check both positive and negative"
|
||||
Wscript.Echo ""
|
||||
Wscript.Echo "Example: cscript /NoLogo check_ad_time.vbs mydomain.com ""0.4"""
|
||||
Wscript.Quit(Err)
|
||||
End Function
|
21
bibliotheque/files/nsclient/scripts/op5/restart_service.ps1
Normal file
21
bibliotheque/files/nsclient/scripts/op5/restart_service.ps1
Normal file
@ -0,0 +1,21 @@
|
||||
# Restart Service Script
|
||||
# Please enable external scripts and external scrips variable before use.
|
||||
|
||||
param (
|
||||
[string[]]$serviceName
|
||||
)
|
||||
Foreach ($Service in $ServiceName)
|
||||
{
|
||||
Restart-Service $ServiceName -ErrorAction SilentlyContinue -ErrorVariable ServiceError
|
||||
If (!$ServiceError) {
|
||||
$Time=Get-Date
|
||||
Write-Host "Restarted service $Service at $Time"
|
||||
}
|
||||
If ($ServiceError) {
|
||||
write-host $error[0]
|
||||
exit 3
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
45
bibliotheque/files/nsclient/scripts/op5/services.vbs
Normal file
45
bibliotheque/files/nsclient/scripts/op5/services.vbs
Normal file
@ -0,0 +1,45 @@
|
||||
' Services.vbs
|
||||
' Script to List running autostarted services
|
||||
' www.computerperformance.co.uk/
|
||||
' Author Guy Thomas http://computerperformance.co.uk/
|
||||
' Version 1.5 December 2005
|
||||
'
|
||||
' Modified by Per Asberg Dec 2010, op5 AB, http://www.op5.com
|
||||
' Modified by Peter Ostlin May 2011, op5 AB, http://www.op5.com
|
||||
' -------------------------------------------------------'
|
||||
Option Explicit
|
||||
Dim icnt, cnt, page, start, objWMIService, objItem, objService, strServiceList
|
||||
Dim colListOfServices, strComputer, strService, Args
|
||||
|
||||
'On Error Resume Next
|
||||
|
||||
' ---------------------------------------------------------
|
||||
|
||||
cnt = 0 ' tot count
|
||||
icnt = 0 ' count listed (returned) services
|
||||
page = 20 ' nr of services to include (pagination)
|
||||
start = 0 ' where to start (pagination)
|
||||
|
||||
Set Args = WScript.Arguments.Named
|
||||
|
||||
If Args.Exists("start") Then start = Cint(Args("start"))
|
||||
|
||||
strComputer = "."
|
||||
Set objWMIService = GetObject("winmgmts:" _
|
||||
& "{impersonationLevel=impersonate}!\\" _
|
||||
& strComputer & "\root\cimv2")
|
||||
Set colListOfServices = objWMIService.ExecQuery _
|
||||
("Select * from Win32_Service WHERE StartMode='auto' AND name != 'NSClientpp'")
|
||||
|
||||
' WMI and VBScript loop
|
||||
For Each objService in colListOfServices
|
||||
If icnt < page AND cnt >= start THEN
|
||||
strServiceList = strServiceList & objService.name & ","
|
||||
icnt = icnt +1
|
||||
End if
|
||||
cnt = cnt + 1
|
||||
Next
|
||||
|
||||
WScript.Echo strServiceList
|
||||
|
||||
' End of WMI script to list services
|
Reference in New Issue
Block a user