Defining services at runtime

Bob Ingraham bobi at netshel.net
Tue May 16 01:43:57 CEST 2006


Comments on your comments are inline.

> -----Original Message-----
> > It looks reality straight forward to work out how to fill out this
> struct,
> > but "char *host_name;" could be a problem. The plugin is only going to
> > know
> > the host address, so I'll need a way to get a hostname from an address.
> >
>
>OK, that makes sense. Of course, the need to get the host_name from the host
>address still remains.

A way to obtain the host_name from an IP address is to use the DNS lookup
function provided by the standard C library: gethostbyaddr()

It's prototype is:

struct hostent *gethostbyaddr(const char *addr, int len, int type);

And here's a snippet of how it works:

extern int h_errno;

static char *herrnos[] = {
        "OK",
        "Host not found",
        "Try again",
        "Non-recoverable error from name-server",
        "No data found",
        "Internal lookup library error"
};

        struct hostent *he;
        struct in_addr ipaddr;
        char *host_addr = "192.168.0.1";

        // convert ip address string to in-addr binary form
        if ((ipaddr.s_addr = inet_addr(host_addr)) == (in_addr_t)(-1))
        {
                fprintf(stderr, "invalid ip-address\n");
                return (-1);
        }

        // Now, perform name lookup
        if ((he = gethostbyaddr(&ipaddr, sizeof(ipaddr), AF_INET)) == NULL)
        {
                if (h_errno < 0 || h_errno > 4) h_errno = 5;
                fprintf(stderr, "Name lookup failed: %s (%d)\n",
herrnos[h_errno], h_errno);
                return (-1);
        }

        printf("Host: %s\n", he->h_name);



>* Submit passive service check results
>
>The old school method of doing this is via the external command file, but I
>presume the new API has a method of doing this? There's some functions in
>broker.h that look like likely candidates, but they don't even have basic
>comments ;) (e.g. broker_service_check).

The NEB Broker API (for module writers,) really only consists of the
following five functions:

nebmodule_init - initialization entry point
nebmodule_deinit - de-init entry point
neb_register_callback - register for an event type
neb_deregister_callback - de-register for an event type
neb_set_module_info - Register info about your module with Nagios

That's it.  Everything else you see consists of internal Nagios functions.
 The functions that you mentioned in broker.h are only used by Nagios to
dispatch events to registered call-backs.  That's all they do.

For example, broker_service_check is just a dispatch routine that loops
through all of the callback routines registered for Service Check events,
and invokes each one with the provided service check information.

That being said, there is an internal function for submitting passive
check results.  It's API is:

int process_passive_service_check(time_t check_time, char *host_name, char
*svc_description, int return_code, char *output);

The parameters are just what their names imply...

Bob



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Developers mailing list