C++ Plugins
Michael Medin
michael at medin.name
Tue Apr 21 21:26:40 CEST 2009
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)
Anyways...
If you are using the "glue" (around the C api) I have written have a
look at for instance this:
http://nsclient.org/nscp/browser/branches/stable/modules/CheckExternalScripts/CheckExternalScripts.cpp
If not then have a look inside the "glue file":
http://nsclient.org/nscp/browser/branches/stable/include/NSCHelper.cpp
But essential if you are not using the glue:
NSCAPI::nagiosReturn wrapReturnString(char *buffer, unsigned int bufLen,
std::wstring str, NSCAPI::nagiosReturn defaultReturnCode /* =
NSCAPI::success */) {
if (str.length() >= bufLen)
return NSCAPI::returnInvalidBufferLen;
strncpy(buffer, str.c_str(), bufLen);
return defaultReturnCode;
}
extern NSCAPI::nagiosReturn NSHandleCommand(const TCHAR* IN_cmd, const
unsigned int IN_argsLen, TCHAR **IN_args, TCHAR *OUT_retBufMessage,
unsigned int IN_retBufMessageLen, TCHAR *OUT_retBufPerf, unsigned int
IN_retBufPerfLen)
{
try {
std::wstring message = _T("my message");
std::wstring perf = _T("my message");
NSCAPI::nagiosReturn ret = NSCAPI::returnOK;
// Wrap strings
ret = wrapReturnString(OUT_retBufMessage, IN_retBufMessageLen,
message, ret);
if (ret == NSCAPI::returnInvalidBufferLen) {
//NSC_LOG_CRITICAL(_T("error in: wrapHandleCommand(...)"));
return NSCAPI::returnIgnored;
}
ret = wrapReturnString(OUT_retBufPerf, IN_retBufPerfLen, perf, ret);
if (ret == NSCAPI::returnInvalidBufferLen) {
//NSC_LOG_CRITICAL(_T("error in: wrapHandleCommand(...)"));
return NSCAPI::returnIgnored;
}
} catch (...) {
//NSC_LOG_CRITICAL(_T("Unknown exception in:
wrapHandleCommand(...)"));
return NSCAPI::returnIgnored;
}
}
In general I would recommend using the glue as it will be simpler to
upgrade then...
// Michael Medin
Christopher McAtackney skrev:
> Hi all,
>
> I'm trying to develop a plug-in for NSClient++ written in C++, but I'm
> unsure of how to return the status code and the check result string
> (e.g. 2 and "Service is Critical").
>
> Are there any examples of C++ plugins online anywhere that I can use
> as a template?
>
> Cheers,
> Chris
>
> ------------------------------------------------------------------------------
> Stay on top of everything new and different, both inside and
> around Java (TM) technology - register by April 22, and save
> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
> 300 plus technical and hands-on sessions. Register today.
> Use priority code J9JMT32. http://p.sf.net/sfu/p
> _______________________________________________
> 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
>
>
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
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