C++ Plugins

Michael Medin michael at medin.name
Mon Apr 27 10:35:46 CEST 2009


On 2009-04-24 12:05, Christopher McAtackney wrote:
> 2009/4/21 Michael Medin <michael at medin.name>:
>   
>> Hello,
>>
>> All the "built in" plugins are avalible as source so it should be pretty
>> simple to figure out.
>> The idea is anyways that you fill the buffer passed to the function from the
>> "core".
>> (this will BTW change in the next major release)
>>     
>
>
> Thanks for the explanation Michael - this should be very helpful.
>   

Ahh...

Sorry, when you mentioned C++ I assumed you were writing extensions.
External scripts can be used "as normal programs" without any specific 
NSClient++ code at all.
Then just follow the regular "writing extensions" guideline for nagios 
and you should be fine.

The difference between external script and extensions are that 
extensions are running "inside" NSClient and thus can do "more" things 
but all in all it is not that much difference so there is no real 
benefit (apart from maybe the forking and such).

// Michael Medin
> I'm curious though, what are the guidelines around writing a C++
> program to be executed as an external script? I've written a simple
> program for checking if the driver name supplied as an arg is loaded
> in the system, but I'm not using any of the above "glue" to do so, I
> just make the checks and printf the output and return the result code.
> Is this sufficient? Here's the code;
>
> #include <stdafx.h>
> #include <windows.h>
> #include <psapi.h>
> #include <tchar.h>
> #include <stdio.h>
>
> #define ARRAY_SIZE 1024
>
> int main(int argc, char* argv[])
> {
> 	LPVOID drivers[ARRAY_SIZE];
> 	DWORD cbNeeded;
> 	int cDrivers, i;
>
> 	if(EnumDeviceDrivers(drivers, sizeof(drivers), &cbNeeded) && cbNeeded
> < sizeof(drivers))
> 	{
> 		TCHAR szDriver[ARRAY_SIZE];
>
> 		cDrivers = cbNeeded / sizeof(drivers[0]);;
>
> 		for (i=0; i < cDrivers; i++ )
> 		{
> 			if(GetDeviceDriverBaseName(drivers[i], szDriver, sizeof(szDriver) /
> sizeof(szDriver[0])))
> 			{
> 				if(argv[1] != NULL && _tcscmp ( szDriver, _T(argv[1])) == 0)	
> 				{
> 					printf("Driver is loaded");
> 					return 0; // OK
> 				}
> 			}
> 		}
>
> 		printf("Driver is not loaded!");
> 		return 2; // CRITICAL
> 	}
> 	else
> 	{
> 		printf("EnumDeviceDrivers failed; array size needed is %d\n",
> cbNeeded / sizeof(LPVOID));
> 		return 3; // UNKNOWN
> 	}
> }
>
>
> It's based off the code here;
> http://msdn.microsoft.com/en-us/library/ms682619(VS.85).aspx
>
> I just drop the compiled program into "ExternalScripts" and add this to nsc.ini;
>
> [External Scripts]
> check_driver = ExternalScripts\Check_Driver.exe <driver-name-here>
>
> Is this an appropriate way to carry-out this check? It works perfectly
> fine so far, but I'm just curious to see if this is a proper way of
> doing things?
>
> Cheers,
> Chris
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20090427/d81cb22a/attachment.html>
-------------- next part --------------
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
-------------- next part --------------
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null


More information about the Users mailing list