log to database

Claus Rosenberger Claus.Rosenberger at rocnet.de
Fri Jul 18 11:08:34 CEST 2003


thats for postgresql
--------------------

# define the service event-handler
define command{
        command_name    write-db-entry-service
        command_line    /usr/bin/printf "%b" "insert into nagiosevents
(ne_times
t,ne_host,ne_service,ne_ip,ne_errtxt,ne_errstatus) values
(unixtime2pgtime($TIME
T$),'$HOSTNAME$','$SERVICEDESC$','$HOSTADDRESS$','$OUTPUT$','$SERVICESTATE$')"
|
 /usr/bin/psql -U nagios erp
        }


# define the host event-handler
define command{
        command_name    write-db-entry-host
        command_line    /usr/bin/printf "%b" "insert into nagiosevents
(ne_times
t,ne_host,ne_ip,ne_errtxt,ne_errstatus) values
(unixtime2pgtime($TIMET$),'$HOSTN
AME$','$HOSTADDRESS$','$OUTPUT$','$HOSTSTATE$')" | /usr/bin/psql -U nagios
erp
        }


# create a simple table and funktion to convert unix-time

CREATE TABLE "nagiosevents" (
   "ne_timest" timestamp NOT NULL,
   "ne_host" varchar(75) NOT NULL,
   "ne_service" varchar(128),
   "ne_ip" varchar(15) NOT NULL,
   "ne_errtxt" varchar(1024) NOT NULL,
   "ne_errstatus" varchar(16) NOT NULL
);

GRANT ALL ON TABLE "nagiosevents" TO nagios;

CREATE FUNCTION unixtime2pgtime(integer) returns timestamp
   as 'select \'epoch\'::timestamp + ($1 || \'seconds\')::interval;'
   language 'sql';


good luck, you have to change some things for mysql perhaps

claus

> --------------------------------------
>    Please visit www.tiscali.co.za
> --------------------------------------
> Hi
>
> I seem to remember someone posting recently that he/she wrote an event
> handler to log data (events/status) to a db (I think MySQL).  Could that
> someone, or anyone else who did anything similar, please send me a copy of
> the code.
>
> I've been looking through the archives but can't seem to find the relevant
> post.
>
> Thanx
>
> :)
> fred
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: VM Ware
> With VMware you can run multiple operating systems on a single machine.
> WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
> same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
> _______________________________________________
> 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
>



-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
_______________________________________________
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