C++ Plugins

Christopher McAtackney cristoir at gmail.com
Fri Apr 24 12:05:40 CEST 2009


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.

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

------------------------------------------------------------------------------
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
_______________________________________________
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