SlideShare una empresa de Scribd logo
1 de 40
Scripting... …on the Windows side
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. Disclaimer! It is not their fault! It is not my fault! It is your fault!
External Scripts Internal Scripts Arguments Scripting: Batch files Wrapped scripts Scripting: VBA Internal Scripts Agenda
Windows monitoring NSClient++ (from a scripters perspecitve)
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) Two kinds of scripts
Enable the check module [/modules] CheckExternalScripts=	# Runs the script NRPEServer=			# NRPE server Each script requires a definition [/settings/External Scripts] check_es_test=scriptsest.bat Options disabled by default (for a reason) allow arguments = false allow nasty characters = false Configuring External Scripts
Enable the check module [/modules] LUAScript= PythonScript= Each script requires a definition [/settings/LUA/Scripts] <alias>=test.lua [/settings/python/Scripts] <alias>=test.py Scripts requires NRPE/NSCA (or NSCP) [/modules] NRPEServer= Configuring Internal Scripts
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 Allow arguments
Allow arguments
Writing our first Scripts The first batch script
Output: Use: echo <text> Don’t forget @echo off (or all commands will be echoed) Exit statuses: Use: exit <code> 0 = OK 1 = Warning 2 = Critical 3 = Unknown NSC.ini syntax: [/settings/External Scripts/scripts] my_script=scriptscript.bat Reference: http://www.ss64.com/nt/ Don’t let preconceptions fool you: batch can actually do a lot! Writing a Script (Batch)
@echo off echo CRITICAL: Everything is not going to be fine exit 2 A basic script (batch)
…SClient++cripts>cmd /ctest.bat CRITICAL: Everything is not going to be fine …SClient++cripts>echo %ERRORLEVEL% 2 Running from Command Line
D:emo>nscp --test NSClient++ 0,4,0,98 2011-09-06 x64 booting... Boot.ini found in: D:/demo//boot.ini Boot order: ini://${shared-path}/nsclient.ini, old://${exe-path}/nsc.ini Activating: ini://${shared-path}/nsclient.ini Creating instance for: ini://${shared-path}:80/nsclient.ini Reading INI settings from: D:/demo//nsclient.ini Loading: D:/demo//nsclient.ini from ini://${shared-path}/nsclient.ini Booted settings subsystem... On crash: restart: NSClientpp Archiving crash dumps in: D:/demo//crash-dumps booting::loading plugins Found: CheckExternalScripts as Processing plugin: CheckExternalScripts.dll as addPlugin(D:/demo//modules/CheckExternalScripts.dll as ) Loading plugin: Check External Scripts as NSClient++ - 0,4,0,98 2011-09-06 Started! Enter command to inject or exit to terminate... Running from NSClient
Enter command to inject or exit to terminate... my_scripts Injecting: my_script... Arguments: Result my_script: WARNING WARNING:Hello World Running from NSClient Command Return Status Return Message
Demo Writing our first Scripts
Writing our first Scripts Killing notepad once and or all!
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: imagenameeq 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. Killing notepad once and for all!
@echo off taskkill /im notepad.exe 1>NUL 2>NUL IF ERRORLEVEL 128 GOTO err IF ERRORLEVEL 0 GOTO ok GOTO unknown :unknown echo UNKNOWN: unknown problem killing notepad... exit /B 3 :err echo CRITICAL: Notepad was not killed... exit /B 1 :ok echo OK: Notepad was killed! exit /B 0 KILL!!!
Demo Killing notepad…
Wrapped scripts Interlude
NSC.ini syntax: [External Scripts] check_bat=scriptsheck_test.bat Or [Wrapped Scripts] check_test=check_test.bat Adding a Script (.bat)
NSC.ini syntax: [External Scripts] check_test=cscript.exe /T:30 /NoLogo scriptsheck_test.vbs Or [Wrapped Scripts] check_test=check_test.vbs Adding a Script (.VBS)
NSC.ini syntax: [External Scripts] check_test=cscript.exe /T:30 /NoLogo scriptsibrapper.vbs scriptsheck_test.vbs Or [Wrapped Scripts] check_test=check_test.vbs Adding a Script (.VBS) w/ libs
NSC.ini syntax: [External Scripts] check_test=cmd /c echo scriptsheck_test.ps1; exit($lastexitcode) | powershell.exe -command - Or [Wrapped Scripts] check_test=check_test.ps1 Adding a Script (.PS1)
[…/wrappings] bat=scriptsSCRIPT% %ARGS% vbs=cscript.exe //T:30 //NoLogo scriptsibrapper.vbs %SCRIPT% %ARGS% ps1=cmd /c echo scriptsSCRIPT% %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) What is wrapped scripts?
Writing your first Scripts Writing a simple VB script
Output: Use: Wscript.StdOut.WriteLine <text> Exit statuses: Use: Wscript.Quit(<code>) 0 = OK 1 = Warning 2 = Critical 3 = Unknown NSC.ini syntax: [External Scripts] check_vbs=cscript.exe //T:30 //NoLogo scriptsheck_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 Writing a Script (VBS)
wscript.echo ”Hello World" wscript.quit(0) Hello_World.vbs
Set <variable name>=CreateObject(“<COM Object>") 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() Object oriented programming (ish)
Demo: Words…
strFile=”c:indows” Dim oFSO Set oFSO=CreateObject("Scripting.FileSystemObject") If oFSO.FileExists(strFile) Then wscript.echo”Yaay!" wscript.quit(0) else wscript.echo“Whhh… what the f***!" wscript.quit(2) end if Are we running windows?
Demo: Are we running Windows?
Using the library Dissecting a VBScript
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++ Internal Scripts
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… Anatomy of an internal script
definit(plugin_id, plugin_alias, script_alias): conf = Settings.get() reg = Registry.get(plugin_id) reg.simple_cmdline('help', get_help) reg.simple_function(‘command', cmd, ‘A command…') conf.set_int('hello', 'python', 42) 	log(Answer: %d'%conf.get_int('hello','python',-1)) def shutdown(): 	log(“Shutting down…”) A basic script
defget_help(arguments): 	return (status.OK, ‘Im not helpful ') def test(arguments): 	core = Core.get() count = len(arguments) (retcode, retmessage, retperf) = core.simple_query(‘CHECK_NSCP’, []) return (status.OK, ‘Life is good… %d'%count) A basic script
Questions? Q&A
Michael Medin michael@medin.name http://www.linkedin.com/in/mickem Information about NSClient++ http://nsclient.org Facebook: facebook.com/nsclient Slides, and examples http://nsclient.org/nscp/conferances/2011/nwcna/ Thank You!

Más contenido relacionado

La actualidad más candente

Cfgmgmt Challenges aren't technical anymore
Cfgmgmt Challenges aren't technical anymoreCfgmgmt Challenges aren't technical anymore
Cfgmgmt Challenges aren't technical anymoreJulien Pivotto
 
Javascript TDD with Jasmine, Karma, and Gulp
Javascript TDD with Jasmine, Karma, and GulpJavascript TDD with Jasmine, Karma, and Gulp
Javascript TDD with Jasmine, Karma, and GulpAll Things Open
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Roberto Franchini
 
Windows attacks - AT is the new black
Windows attacks - AT is the new blackWindows attacks - AT is the new black
Windows attacks - AT is the new blackChris Gates
 
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesWindows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesPeter Hlavaty
 
Jenkins Evolutions - JEEConf 2012
Jenkins Evolutions - JEEConf 2012Jenkins Evolutions - JEEConf 2012
Jenkins Evolutions - JEEConf 2012Anton Arhipov
 
Mastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionMastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionSasha Goldshtein
 
Automated User Tests with Apache Flex
Automated User Tests with Apache FlexAutomated User Tests with Apache Flex
Automated User Tests with Apache FlexGert Poppe
 
Introduction to .NET Performance Measurement
Introduction to .NET Performance MeasurementIntroduction to .NET Performance Measurement
Introduction to .NET Performance MeasurementSasha Goldshtein
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQLRoberto Franchini
 
Супер быстрая автоматизация тестирования на iOS
Супер быстрая автоматизация тестирования на iOSСупер быстрая автоматизация тестирования на iOS
Супер быстрая автоматизация тестирования на iOSSQALab
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent codeDror Helper
 
Bypassing patchguard on Windows 8.1 and Windows 10
Bypassing patchguard on Windows 8.1 and Windows 10Bypassing patchguard on Windows 8.1 and Windows 10
Bypassing patchguard on Windows 8.1 and Windows 10Honorary_BoT
 
Se lancer dans l'aventure microservices avec Spring Cloud - Julien Roy
Se lancer dans l'aventure microservices avec Spring Cloud - Julien RoySe lancer dans l'aventure microservices avec Spring Cloud - Julien Roy
Se lancer dans l'aventure microservices avec Spring Cloud - Julien Royekino
 

La actualidad más candente (20)

Cfgmgmt Challenges aren't technical anymore
Cfgmgmt Challenges aren't technical anymoreCfgmgmt Challenges aren't technical anymore
Cfgmgmt Challenges aren't technical anymore
 
ruxc0n 2012
ruxc0n 2012ruxc0n 2012
ruxc0n 2012
 
Javascript TDD with Jasmine, Karma, and Gulp
Javascript TDD with Jasmine, Karma, and GulpJavascript TDD with Jasmine, Karma, and Gulp
Javascript TDD with Jasmine, Karma, and Gulp
 
.NET Debugging Workshop
.NET Debugging Workshop.NET Debugging Workshop
.NET Debugging Workshop
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
 
Windows attacks - AT is the new black
Windows attacks - AT is the new blackWindows attacks - AT is the new black
Windows attacks - AT is the new black
 
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesWindows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
 
Jenkins Evolutions - JEEConf 2012
Jenkins Evolutions - JEEConf 2012Jenkins Evolutions - JEEConf 2012
Jenkins Evolutions - JEEConf 2012
 
Node.js essentials
 Node.js essentials Node.js essentials
Node.js essentials
 
Mastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionMastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and Production
 
Automated User Tests with Apache Flex
Automated User Tests with Apache FlexAutomated User Tests with Apache Flex
Automated User Tests with Apache Flex
 
Introduction to .NET Performance Measurement
Introduction to .NET Performance MeasurementIntroduction to .NET Performance Measurement
Introduction to .NET Performance Measurement
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQL
 
Супер быстрая автоматизация тестирования на iOS
Супер быстрая автоматизация тестирования на iOSСупер быстрая автоматизация тестирования на iOS
Супер быстрая автоматизация тестирования на iOS
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent code
 
Everything as a code
Everything as a codeEverything as a code
Everything as a code
 
OHHttpStubs
OHHttpStubsOHHttpStubs
OHHttpStubs
 
Bypassing patchguard on Windows 8.1 and Windows 10
Bypassing patchguard on Windows 8.1 and Windows 10Bypassing patchguard on Windows 8.1 and Windows 10
Bypassing patchguard on Windows 8.1 and Windows 10
 
Se lancer dans l'aventure microservices avec Spring Cloud - Julien Roy
Se lancer dans l'aventure microservices avec Spring Cloud - Julien RoySe lancer dans l'aventure microservices avec Spring Cloud - Julien Roy
Se lancer dans l'aventure microservices avec Spring Cloud - Julien Roy
 
Testing with PostgreSQL
Testing with PostgreSQLTesting with PostgreSQL
Testing with PostgreSQL
 

Destacado

Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...
Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...
Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...Nagios
 
Nagios Conference 2011 - Jared Bird - Using Nagios As A Security Tool
Nagios Conference 2011 - Jared Bird - Using Nagios As A Security ToolNagios Conference 2011 - Jared Bird - Using Nagios As A Security Tool
Nagios Conference 2011 - Jared Bird - Using Nagios As A Security ToolNagios
 
Nagios Conference 2012 - Ethan Galstad - Keynote
Nagios Conference 2012 - Ethan Galstad - KeynoteNagios Conference 2012 - Ethan Galstad - Keynote
Nagios Conference 2012 - Ethan Galstad - KeynoteNagios
 
Nagios Conference 2011 - Arun Ramanathan - Environment Monitoring With Nagios
Nagios Conference 2011 - Arun Ramanathan - Environment Monitoring With NagiosNagios Conference 2011 - Arun Ramanathan - Environment Monitoring With Nagios
Nagios Conference 2011 - Arun Ramanathan - Environment Monitoring With NagiosNagios
 

Destacado (6)

Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...
Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...
Nagios Conference 2011 - Mike Weber - Training: Monitoring Linux Mail Servers...
 
Nagios
NagiosNagios
Nagios
 
Nagios
NagiosNagios
Nagios
 
Nagios Conference 2011 - Jared Bird - Using Nagios As A Security Tool
Nagios Conference 2011 - Jared Bird - Using Nagios As A Security ToolNagios Conference 2011 - Jared Bird - Using Nagios As A Security Tool
Nagios Conference 2011 - Jared Bird - Using Nagios As A Security Tool
 
Nagios Conference 2012 - Ethan Galstad - Keynote
Nagios Conference 2012 - Ethan Galstad - KeynoteNagios Conference 2012 - Ethan Galstad - Keynote
Nagios Conference 2012 - Ethan Galstad - Keynote
 
Nagios Conference 2011 - Arun Ramanathan - Environment Monitoring With Nagios
Nagios Conference 2011 - Arun Ramanathan - Environment Monitoring With NagiosNagios Conference 2011 - Arun Ramanathan - Environment Monitoring With Nagios
Nagios Conference 2011 - Arun Ramanathan - Environment Monitoring With Nagios
 

Similar a Nagios Conference 2011 - Michael Medin - Workshop: Scripting On The Windows Side

[COSCUP 2021] A trip about how I contribute to LLVM
[COSCUP 2021] A trip about how I contribute to LLVM[COSCUP 2021] A trip about how I contribute to LLVM
[COSCUP 2021] A trip about how I contribute to LLVMDouglas Chen
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and TechniquesBala Subra
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging TechniquesBala Subra
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...tutorialsruby
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...tutorialsruby
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)Soshi Nemoto
 
Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linuxAjin Abraham
 
Batch programming and Viruses
Batch programming and VirusesBatch programming and Viruses
Batch programming and VirusesAkshay Saini
 
How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]Devon Bernard
 
Batch file programming
Batch file programmingBatch file programming
Batch file programmingswapnil kapate
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayAnne Nicolas
 
OverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxOverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxalfred4lewis58146
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone CivettaCocoaHeads France
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox testsKevin Beeman
 
Lets make better scripts
Lets make better scriptsLets make better scripts
Lets make better scriptsMichael Boelen
 

Similar a Nagios Conference 2011 - Michael Medin - Workshop: Scripting On The Windows Side (20)

A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 
[COSCUP 2021] A trip about how I contribute to LLVM
[COSCUP 2021] A trip about how I contribute to LLVM[COSCUP 2021] A trip about how I contribute to LLVM
[COSCUP 2021] A trip about how I contribute to LLVM
 
Node.js debugging
Node.js debuggingNode.js debugging
Node.js debugging
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
 
Intro django
Intro djangoIntro django
Intro django
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Valgrind
ValgrindValgrind
Valgrind
 
lec4.docx
lec4.docxlec4.docx
lec4.docx
 
Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linux
 
Batch programming and Viruses
Batch programming and VirusesBatch programming and Viruses
Batch programming and Viruses
 
How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]
 
Batch file programming
Batch file programmingBatch file programming
Batch file programming
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops way
 
OverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docxOverviewIn this assignment you will write your own shell i.docx
OverviewIn this assignment you will write your own shell i.docx
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone Civetta
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox tests
 
Lets make better scripts
Lets make better scriptsLets make better scripts
Lets make better scripts
 

Más de Nagios

Nagios XI Best Practices
Nagios XI Best PracticesNagios XI Best Practices
Nagios XI Best PracticesNagios
 
Jesse Olson - Nagios Log Server Architecture Overview
Jesse Olson - Nagios Log Server Architecture OverviewJesse Olson - Nagios Log Server Architecture Overview
Jesse Olson - Nagios Log Server Architecture OverviewNagios
 
Trevor McDonald - Nagios XI Under The Hood
Trevor McDonald  - Nagios XI Under The HoodTrevor McDonald  - Nagios XI Under The Hood
Trevor McDonald - Nagios XI Under The HoodNagios
 
Sean Falzon - Nagios - Resilient Notifications
Sean Falzon - Nagios - Resilient NotificationsSean Falzon - Nagios - Resilient Notifications
Sean Falzon - Nagios - Resilient NotificationsNagios
 
Marcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise Edition
Marcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise EditionMarcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise Edition
Marcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise EditionNagios
 
Janice Singh - Writing Custom Nagios Plugins
Janice Singh - Writing Custom Nagios PluginsJanice Singh - Writing Custom Nagios Plugins
Janice Singh - Writing Custom Nagios PluginsNagios
 
Dave Williams - Nagios Log Server - Practical Experience
Dave Williams - Nagios Log Server - Practical ExperienceDave Williams - Nagios Log Server - Practical Experience
Dave Williams - Nagios Log Server - Practical ExperienceNagios
 
Mike Weber - Nagios and Group Deployment of Service Checks
Mike Weber - Nagios and Group Deployment of Service ChecksMike Weber - Nagios and Group Deployment of Service Checks
Mike Weber - Nagios and Group Deployment of Service ChecksNagios
 
Mike Guthrie - Revamping Your 10 Year Old Nagios Installation
Mike Guthrie - Revamping Your 10 Year Old Nagios InstallationMike Guthrie - Revamping Your 10 Year Old Nagios Installation
Mike Guthrie - Revamping Your 10 Year Old Nagios InstallationNagios
 
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...Nagios
 
Matt Bruzek - Monitoring Your Public Cloud With Nagios
Matt Bruzek - Monitoring Your Public Cloud With NagiosMatt Bruzek - Monitoring Your Public Cloud With Nagios
Matt Bruzek - Monitoring Your Public Cloud With NagiosNagios
 
Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.
Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.
Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.Nagios
 
Eric Loyd - Fractal Nagios
Eric Loyd - Fractal NagiosEric Loyd - Fractal Nagios
Eric Loyd - Fractal NagiosNagios
 
Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...
Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...
Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...Nagios
 
Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...
Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...
Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...Nagios
 
Nagios World Conference 2015 - Scott Wilkerson Opening
Nagios World Conference 2015 - Scott Wilkerson OpeningNagios World Conference 2015 - Scott Wilkerson Opening
Nagios World Conference 2015 - Scott Wilkerson OpeningNagios
 
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios CoreNrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios CoreNagios
 
Nagios Log Server - Features
Nagios Log Server - FeaturesNagios Log Server - Features
Nagios Log Server - FeaturesNagios
 
Nagios Network Analyzer - Features
Nagios Network Analyzer - FeaturesNagios Network Analyzer - Features
Nagios Network Analyzer - FeaturesNagios
 
Nagios Conference 2014 - Dorance Martinez Cortes - Customizing Nagios
Nagios Conference 2014 - Dorance Martinez Cortes - Customizing NagiosNagios Conference 2014 - Dorance Martinez Cortes - Customizing Nagios
Nagios Conference 2014 - Dorance Martinez Cortes - Customizing NagiosNagios
 

Más de Nagios (20)

Nagios XI Best Practices
Nagios XI Best PracticesNagios XI Best Practices
Nagios XI Best Practices
 
Jesse Olson - Nagios Log Server Architecture Overview
Jesse Olson - Nagios Log Server Architecture OverviewJesse Olson - Nagios Log Server Architecture Overview
Jesse Olson - Nagios Log Server Architecture Overview
 
Trevor McDonald - Nagios XI Under The Hood
Trevor McDonald  - Nagios XI Under The HoodTrevor McDonald  - Nagios XI Under The Hood
Trevor McDonald - Nagios XI Under The Hood
 
Sean Falzon - Nagios - Resilient Notifications
Sean Falzon - Nagios - Resilient NotificationsSean Falzon - Nagios - Resilient Notifications
Sean Falzon - Nagios - Resilient Notifications
 
Marcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise Edition
Marcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise EditionMarcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise Edition
Marcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise Edition
 
Janice Singh - Writing Custom Nagios Plugins
Janice Singh - Writing Custom Nagios PluginsJanice Singh - Writing Custom Nagios Plugins
Janice Singh - Writing Custom Nagios Plugins
 
Dave Williams - Nagios Log Server - Practical Experience
Dave Williams - Nagios Log Server - Practical ExperienceDave Williams - Nagios Log Server - Practical Experience
Dave Williams - Nagios Log Server - Practical Experience
 
Mike Weber - Nagios and Group Deployment of Service Checks
Mike Weber - Nagios and Group Deployment of Service ChecksMike Weber - Nagios and Group Deployment of Service Checks
Mike Weber - Nagios and Group Deployment of Service Checks
 
Mike Guthrie - Revamping Your 10 Year Old Nagios Installation
Mike Guthrie - Revamping Your 10 Year Old Nagios InstallationMike Guthrie - Revamping Your 10 Year Old Nagios Installation
Mike Guthrie - Revamping Your 10 Year Old Nagios Installation
 
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
 
Matt Bruzek - Monitoring Your Public Cloud With Nagios
Matt Bruzek - Monitoring Your Public Cloud With NagiosMatt Bruzek - Monitoring Your Public Cloud With Nagios
Matt Bruzek - Monitoring Your Public Cloud With Nagios
 
Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.
Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.
Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.
 
Eric Loyd - Fractal Nagios
Eric Loyd - Fractal NagiosEric Loyd - Fractal Nagios
Eric Loyd - Fractal Nagios
 
Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...
Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...
Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...
 
Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...
Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...
Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...
 
Nagios World Conference 2015 - Scott Wilkerson Opening
Nagios World Conference 2015 - Scott Wilkerson OpeningNagios World Conference 2015 - Scott Wilkerson Opening
Nagios World Conference 2015 - Scott Wilkerson Opening
 
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios CoreNrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
 
Nagios Log Server - Features
Nagios Log Server - FeaturesNagios Log Server - Features
Nagios Log Server - Features
 
Nagios Network Analyzer - Features
Nagios Network Analyzer - FeaturesNagios Network Analyzer - Features
Nagios Network Analyzer - Features
 
Nagios Conference 2014 - Dorance Martinez Cortes - Customizing Nagios
Nagios Conference 2014 - Dorance Martinez Cortes - Customizing NagiosNagios Conference 2014 - Dorance Martinez Cortes - Customizing Nagios
Nagios Conference 2014 - Dorance Martinez Cortes - Customizing Nagios
 

Último

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Último (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

Nagios Conference 2011 - Michael Medin - Workshop: Scripting On The Windows Side

  • 1. Scripting... …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. Disclaimer! 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 Agenda
  • 4. Windows monitoring 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) Two kinds of scripts
  • 6. Enable the check module [/modules] CheckExternalScripts= # Runs the script NRPEServer= # NRPE server Each script requires a definition [/settings/External Scripts] check_es_test=scriptsest.bat Options disabled by default (for a reason) allow arguments = false allow nasty characters = false Configuring External Scripts
  • 7. Enable the check module [/modules] LUAScript= PythonScript= Each script requires a definition [/settings/LUA/Scripts] <alias>=test.lua [/settings/python/Scripts] <alias>=test.py Scripts requires NRPE/NSCA (or NSCP) [/modules] NRPEServer= Configuring Internal Scripts
  • 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 Allow arguments
  • 10. Writing our first Scripts The first batch script
  • 11. Output: Use: echo <text> Don’t forget @echo off (or all commands will be echoed) Exit statuses: Use: exit <code> 0 = OK 1 = Warning 2 = Critical 3 = Unknown NSC.ini syntax: [/settings/External Scripts/scripts] my_script=scriptscript.bat Reference: http://www.ss64.com/nt/ Don’t let preconceptions fool you: batch can actually do a lot! Writing a Script (Batch)
  • 12. @echo off echo CRITICAL: Everything is not going to be fine exit 2 A basic script (batch)
  • 13. …SClient++cripts>cmd /ctest.bat CRITICAL: Everything is not going to be fine …SClient++cripts>echo %ERRORLEVEL% 2 Running from Command Line
  • 14. D:emo>nscp --test NSClient++ 0,4,0,98 2011-09-06 x64 booting... Boot.ini found in: D:/demo//boot.ini Boot order: ini://${shared-path}/nsclient.ini, old://${exe-path}/nsc.ini Activating: ini://${shared-path}/nsclient.ini Creating instance for: ini://${shared-path}:80/nsclient.ini Reading INI settings from: D:/demo//nsclient.ini Loading: D:/demo//nsclient.ini from ini://${shared-path}/nsclient.ini Booted settings subsystem... On crash: restart: NSClientpp Archiving crash dumps in: D:/demo//crash-dumps booting::loading plugins Found: CheckExternalScripts as Processing plugin: CheckExternalScripts.dll as addPlugin(D:/demo//modules/CheckExternalScripts.dll as ) Loading plugin: Check External Scripts as NSClient++ - 0,4,0,98 2011-09-06 Started! Enter command to inject or exit to terminate... Running from NSClient
  • 15. Enter command to inject or exit to terminate... my_scripts Injecting: my_script... Arguments: Result my_script: WARNING WARNING:Hello World Running from NSClient Command Return Status Return Message
  • 16. Demo Writing our first Scripts
  • 17. Writing our first Scripts 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: imagenameeq 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. Killing notepad once and for all!
  • 19. @echo off taskkill /im notepad.exe 1>NUL 2>NUL IF ERRORLEVEL 128 GOTO err IF ERRORLEVEL 0 GOTO ok GOTO unknown :unknown echo UNKNOWN: unknown problem killing notepad... exit /B 3 :err echo CRITICAL: Notepad was not killed... exit /B 1 :ok echo OK: Notepad was killed! exit /B 0 KILL!!!
  • 22. NSC.ini syntax: [External Scripts] check_bat=scriptsheck_test.bat Or [Wrapped Scripts] check_test=check_test.bat Adding a Script (.bat)
  • 23. NSC.ini syntax: [External Scripts] check_test=cscript.exe /T:30 /NoLogo scriptsheck_test.vbs Or [Wrapped Scripts] check_test=check_test.vbs Adding a Script (.VBS)
  • 24. NSC.ini syntax: [External Scripts] check_test=cscript.exe /T:30 /NoLogo scriptsibrapper.vbs scriptsheck_test.vbs Or [Wrapped Scripts] check_test=check_test.vbs Adding a Script (.VBS) w/ libs
  • 25. NSC.ini syntax: [External Scripts] check_test=cmd /c echo scriptsheck_test.ps1; exit($lastexitcode) | powershell.exe -command - Or [Wrapped Scripts] check_test=check_test.ps1 Adding a Script (.PS1)
  • 26. […/wrappings] bat=scriptsSCRIPT% %ARGS% vbs=cscript.exe //T:30 //NoLogo scriptsibrapper.vbs %SCRIPT% %ARGS% ps1=cmd /c echo scriptsSCRIPT% %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) What is wrapped scripts?
  • 27. Writing your first Scripts Writing a simple VB script
  • 28. Output: Use: Wscript.StdOut.WriteLine <text> Exit statuses: Use: Wscript.Quit(<code>) 0 = OK 1 = Warning 2 = Critical 3 = Unknown NSC.ini syntax: [External Scripts] check_vbs=cscript.exe //T:30 //NoLogo scriptsheck_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 Writing a Script (VBS)
  • 29. wscript.echo ”Hello World" wscript.quit(0) Hello_World.vbs
  • 30. Set <variable name>=CreateObject(“<COM Object>") 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() Object oriented programming (ish)
  • 32. strFile=”c:indows” Dim oFSO Set oFSO=CreateObject("Scripting.FileSystemObject") If oFSO.FileExists(strFile) Then wscript.echo”Yaay!" wscript.quit(0) else wscript.echo“Whhh… what the f***!" wscript.quit(2) end if Are we running windows?
  • 33. Demo: Are we running Windows?
  • 34. Using the library 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++ Internal Scripts
  • 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… Anatomy of an internal script
  • 37. definit(plugin_id, plugin_alias, script_alias): conf = Settings.get() reg = Registry.get(plugin_id) reg.simple_cmdline('help', get_help) reg.simple_function(‘command', cmd, ‘A command…') conf.set_int('hello', 'python', 42) log(Answer: %d'%conf.get_int('hello','python',-1)) def shutdown(): log(“Shutting down…”) A basic script
  • 38. defget_help(arguments): return (status.OK, ‘Im not helpful ') def test(arguments): core = Core.get() count = len(arguments) (retcode, retmessage, retperf) = core.simple_query(‘CHECK_NSCP’, []) return (status.OK, ‘Life is good… %d'%count) A basic script
  • 40. Michael Medin michael@medin.name http://www.linkedin.com/in/mickem Information about NSClient++ http://nsclient.org Facebook: facebook.com/nsclient Slides, and examples http://nsclient.org/nscp/conferances/2011/nwcna/ Thank You!

Notas del editor

  1. Hello my name is Michael Medin.I am from Stockholm, Sweden.I will give this in English just because I think everyone else does...If there are any questions or such just chime in.Feel free to ask questions in Swedish if you wish.
  2. Standard Disclaimer - My views (not anyone else&apos;s) - Not peer reviewed so I could be lying to you. - If you 2 billion dollar servers crash: life sucksLets simplify this a bit…
  3. cmd /c is because we need to capture the “exit code” normally exit will exit all running shellsWe get the message but no error codeUse echo %ERRORLEVEL% to display the exit code
  4. We run the scriptGet the error code (Critical) and the Message (...)But we get no performance data
  5. We run the scriptGet the error code (Critical) and the Message (...)But we get no performance data
  6. 2 minutes
  7. 2 minutes
  8. 2 minutes