Presentation is loading. Please wait.

Presentation is loading. Please wait.

…on the Windows side.  These slides represent the work and opinions of the author and do not constitute official positions of any organization sponsoring.

Similar presentations


Presentation on theme: "…on the Windows side.  These slides represent the work and opinions of the author and do not constitute official positions of any organization sponsoring."— Presentation transcript:

1 …on the Windows side

2  These slides represent the work and opinions of the author and do not constitute official positions of any organization sponsoring the author’s work  This material has not been peer reviewed and is presented here as-is with the permission of the author.  The author assumes no liability for any content or opinion expressed in this presentation and or use of content herein. It is not their fault! It is not my fault! It is your fault!

3  External Scripts  Internal Scripts  Arguments  Scripting: Batch files  Wrapped scripts  Scripting: VBA  Internal Scripts

4 NSClient++ (from a scripters perspecitve)

5  External Scripts ◦ The normal kind of scripts ◦ Can be written in:  Batch  VBA/VBScript (pretty popular on Windows)  Powershell (a rather strange language) ◦ But also:  Perl, python, bash, etc etc…  Internal Scripts ◦ Can interact with (other) internal commands ◦ Can access settings ◦ Can hold state ◦ Can be written in:  Lua  Python (requires python on the machine)

6 1. Enable the check module [/modules] CheckExternalScripts=# Runs the script NRPEServer=# NRPE server 2. Each script requires a definition [/settings/External Scripts] check_es_test=scripts\test.bat 3. Options disabled by default (for a reason) allow arguments = false allow nasty characters = false

7 1. Enable the check module [/modules] LUAScript= PythonScript= 2. Each script requires a definition [/settings/LUA/Scripts] =test.lua [/settings/python/Scripts] =test.py 3. Scripts requires NRPE/NSCA (or NSCP) [/modules] NRPEServer=

8  Can be configured in many places ◦ Is probably more confusing then it is worth  The server module ◦ Means NO commands can have arguments  The script module ◦ Means NO external script can have arguments

9 NRPENSClient++ExternalScriptsscript.batscript.vbsCheckSystemCheckCPUCheckMemCheckEventLog CheckTaskSched

10 The first batch script

11  Output: ◦ Use: echo ◦ Don’t forget @echo off (or all commands will be echoed)  Exit statuses: ◦ Use: exit  0 = OK  1 = Warning  2 = Critical  3 = Unknown  NSC.ini syntax: [/settings/External Scripts/scripts] my_script=scripts\script.bat  Reference: ◦ http://www.ss64.com/nt/  Don’t let preconceptions fool you: batch can actually do a lot!

12

13 …\NSClient++\scripts>cmd /c test.bat CRITICAL: Everything is not going to be fine …\NSClient++\scripts>echo %ERRORLEVEL% 2

14

15 Return Status Return Message Command

16 Writing our first Scripts

17 Killing notepad once and or all!

18 TASKKILL [/S dator [/U användarnamn [/P lösenord]]]] { [/FI filter] [/PID process-ID | /IM avbildning] } [/T][/F] Beskrivning: Det här verktyget används för att avsluta en eller flera aktiviteter utifrån process-ID (PID) eller avbildningsnamn. Parameterlista: … /FI filter Använder ett filter för att välja aktiviteter. Jokertecknet * kan användas, t.ex: imagename eq note* /PID process-ID Anger process-ID för den process som ska avbrytas. Använd kommandot Tasklist för att hämta process-ID /IM avbildning Anger avbildning för den process som för den process som ska avslutas. Jokertecknet * användas för att ange alla aktiviteter eller avbildningar.

19

20 Killing notepad…

21 Interlude

22  NSC.ini syntax: ◦ [External Scripts] ◦ check_bat=scripts\check_test.bat  Or ◦ [Wrapped Scripts] ◦ check_test=check_test.bat

23  NSC.ini syntax: ◦ [External Scripts] ◦ check_test=cscript.exe /T:30 /NoLogo scripts\check_test.vbs  Or ◦ [Wrapped Scripts] ◦ check_test=check_test.vbs

24  NSC.ini syntax: ◦ [External Scripts] ◦ check_test=cscript.exe /T:30 /NoLogo scripts\lib\wrapper.vbs scripts\check_test.vbs  Or ◦ [Wrapped Scripts] ◦ check_test=check_test.vbs

25  NSC.ini syntax: ◦ [External Scripts] ◦ check_test=cmd /c echo scripts\check_test.ps1; exit($lastexitcode) | powershell.exe -command -  Or ◦ [Wrapped Scripts] ◦ check_test=check_test.ps1

26 […/wrappings] bat=scripts\%SCRIPT% %ARGS% vbs=cscript.exe //T:30 //NoLogo scripts\lib\wrapper.vbs %SCRIPT% %ARGS% ps1=cmd /c echo scripts\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command - […/wrapped scripts] check_test_vbs=check_test.vbs /arg1:1 /variable:1 check_test_ps1=check_test.ps1 arg1 arg2 check_test_bat=check_test.bat $ARG1$ arg2 check_battery=check_battery.vbs check_printer=check_printer.vbs ; So essentially it is a macro! (but a nice one)

27 Writing a simple VB script

28  Output: ◦ Use: Wscript.StdOut.WriteLine  Exit statuses: ◦ Use: Wscript.Quit( )  0 = OK  1 = Warning  2 = Critical  3 = Unknown  NSC.ini syntax: [External Scripts] check_vbs=cscript.exe //T:30 //NoLogo scripts\check_vbs.vbs //T:30 Is the timeout and might need to be changed.  Reference: ◦ http://msdn.microsoft.com/en-us/library/t0aew7h6(VS.85).aspx

29

30  Set =CreateObject(“ ")  There is A LOT of objects you can create  A nice way to interact with other applications  For instance: ◦ Set objWord = CreateObject("Word.Application") ◦ objWord.Visible = True ◦ Set objDoc = objWord.Documents.Add() ◦ Set objSelection = objWord.Selection ◦ objSelection.Font.Name = “Comic Sans MS" ◦ objSelection.Font.Size = “28" ◦ objSelection.TypeText “Hello World" ◦ objSelection.TypeParagraph() ◦ objSelection.Font.Size = "14" ◦ objSelection.TypeText "" & Date() ◦ objSelection.TypeParagraph()

31 Words…

32

33 Are we running Windows?

34 Dissecting a VBScript

35  Can be used to extend NSClient++  Are very powerful  A good way to: ◦ Alter things you do not like ◦ Create advanced things  Are written in Lua or Python  Possibly unsafe ◦ Runs inside NSClient++

36  Internal scripts are fundamentally different  One script is NOT equals to one function ◦ A script (at startup) can:  Register query (commands) handlers  Register submission (passive checks) handlers  Register exec handlers  Register configuration  Access configuration ◦ Handlers can:  Execute queries (commands)  Submit submissions (passive checks)  Etc etc…

37

38

39 Questions?

40


Download ppt "…on the Windows side.  These slides represent the work and opinions of the author and do not constitute official positions of any organization sponsoring."

Similar presentations


Ads by Google