<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
On 2009-04-24 12:05, Christopher McAtackney wrote:
<blockquote
cite="mid:c4ae53ee0904240305m55feaeb3y706c682aaecf2bcd@mail.gmail.com"
type="cite">
<pre wrap="">2009/4/21 Michael Medin <a class="moz-txt-link-rfc2396E" href="mailto:michael@medin.name"><michael@medin.name></a>:
</pre>
<blockquote type="cite">
<pre wrap="">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)
</pre>
</blockquote>
<pre wrap=""><!---->
Thanks for the explanation Michael - this should be very helpful.
</pre>
</blockquote>
<br>
Ahh...<br>
<br>
Sorry, when you mentioned C++ I assumed you were writing extensions.<br>
External scripts can be used "as normal programs" without any specific
NSClient++ code at all.<br>
Then just follow the regular "writing extensions" guideline for nagios
and you should be fine.<br>
<br>
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).<br>
<br>
// Michael Medin<br>
<blockquote
cite="mid:c4ae53ee0904240305m55feaeb3y706c682aaecf2bcd@mail.gmail.com"
type="cite">
<pre wrap="">
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;
<a class="moz-txt-link-freetext" href="http://msdn.microsoft.com/en-us/library/ms682619(VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms682619(VS.85).aspx</a>
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
</pre>
</blockquote>
<br>
</body>
</html>