Nagios Plugin for Cacti (NPC) Released

General discussion about Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
User avatar
divagater
Cacti User
Posts: 191
Joined: Wed Nov 17, 2004 5:22 pm
Location: Chapel Hill, NC.
Contact:

Nagios Plugin for Cacti (NPC) Released

Post by divagater »

NOTE: This thread was for the original alpha release of NPC in 2005 and is now obsolete. The current thread for NPC 2.x is: http://forums.cacti.net/viewtopic.php?t=26540


I have an alpha release ready for the folks who are interested to check out. NPC 0.1.1a can be downloaded from http://www.divagater.com/npc/

I have been running it in my production environment for a little over a month and have not noticed any major issues like data inconsistency with Nagios.

For those interested in making changes or just looking under the covers I apologize in advance for the code. I am a PHP novice and what I wrote, although functional, would not meet the standards of good MVC design.

If you have trouble with anything I will do my best to answer questions.

Cheers,
Billy
Last edited by divagater on Fri Jun 26, 2009 9:09 pm, edited 1 time in total.
ancery
Posts: 11
Joined: Thu Nov 03, 2005 4:43 am

Post by ancery »

GREAT JOB!!!

i've expected it for a long time, thx for your great efforts,

i'll try it immediately, THANK U!!
farhan
Posts: 47
Joined: Sat Nov 12, 2005 6:55 am

Nagios Plugin Release

Post by farhan »

Awsome Work man.

Can we restrict users to view only specific hosts/services under nagios

plugin. Like we can restrict users to specific Graph under User

Management in cacti.

Thanks,
r_chetanjain
Cacti User
Posts: 83
Joined: Fri Aug 22, 2003 4:33 am

gr888 Job

Post by r_chetanjain »

Gr888 dude....will expect more addtions to this Addon....Waiting for the status map to be integrated to cacti....

Chetan jain
User avatar
divagater
Cacti User
Posts: 191
Joined: Wed Nov 17, 2004 5:22 pm
Location: Chapel Hill, NC.
Contact:

Post by divagater »

Can we restrict users to view only specific hosts/services under nagios plugin. Like we can restrict users to specific Graph under User Management in cacti.
I was just thinking about this after getting your email and I think it will be very easy to do. With the current alpha release it can't be done but I will try to get another release out this weekend with the improved permissions.

Cheers,
Billy
macdonaldc
Posts: 25
Joined: Thu Nov 10, 2005 12:00 am

Post by macdonaldc »

Hi Billy,

Cant wait to get this going. Im having a small issue. I got as far as the make. Can u shed some light as to where i should look? I should note that i just had installed Nagios (from my SuSe dvd). That being the case i put the database info in the config file to point to my cacti info. Is this the problem?

BetaServer:/usr/lib/nagios/plugins # make
gcc -g -O2 -Wall -o inserter.o inserter.c -shared -I../include -I/usr/include/mysql -lmysqlclient -fPIC
inserter.c:43:25: error: mysql/mysql.h: No such file or directory
inserter.c:44:26: error: mysql/errmsg.h: No such file or directory
inserter.c:47:35: error: ../include/nebmodules.h: No such file or directory
inserter.c:48:37: error: ../include/nebcallbacks.h: No such file or directory
inserter.c:49:35: error: ../include/nebstructs.h: No such file or directory
inserter.c:50:31: error: ../include/broker.h: No such file or directory
inserter.c:53:31: error: ../include/config.h: No such file or directory
inserter.c:54:31: error: ../include/common.h: No such file or directory
inserter.c:55:31: error: ../include/nagios.h: No such file or directory
inserter.c:56:32: error: ../include/objects.h: No such file or directory
inserter.c:64: warning: type defaults to âintâ in declaration of âNEB_API_VERSIONâ
inserter.c:64: warning: parameter names (without types) in function declaration
inserter.c:64: warning: data definition has no type or storage class
inserter.c:78: error: syntax error before â*â token
inserter.c:78: warning: type defaults to âintâ in declaration of âhostgroup_listâ
inserter.c:78: warning: data definition has no type or storage class
inserter.c:79: error: syntax error before â*â token
inserter.c:79: warning: type defaults to âintâ in declaration of âservicegroup_listâ
inserter.c:79: warning: data definition has no type or storage class
inserter.c:80: error: syntax error before â*â token
inserter.c:80: warning: type defaults to âintâ in declaration of âhost_listâ
inserter.c:80: warning: data definition has no type or storage class
inserter.c:81: error: syntax error before â*â token
inserter.c:81: warning: type defaults to âintâ in declaration of âservice_listâ
inserter.c:81: warning: data definition has no type or storage class
inserter.c:96: error: syntax error before âmysqlâ
inserter.c:96: warning: type defaults to âintâ in declaration of âmysqlâ
inserter.c:96: warning: data definition has no type or storage class
inserter.c:121: error: âFALSEâ undeclared here (not in a function)
inserter.c:124: error: syntax error before ânebmoduleâ
inserter.c: In function ânebmodule_initâ:
inserter.c:130: error: âhandleâ undeclared (first use in this function)
inserter.c:130: error: (Each undeclared identifier is reported only once
inserter.c:130: error: for each function it appears in.)
inserter.c:132: warning: implicit declaration of function âwrite_to_logs_and_consoleâ
inserter.c:132: error: âNSLOG_INFO_MESSAGEâ undeclared (first use in this function)
inserter.c:132: error: âTRUEâ undeclared (first use in this function)
inserter.c:137: warning: implicit declaration of function âschedule_new_eventâ
inserter.c:137: error: âEVENT_USER_FUNCTIONâ undeclared (first use in this function)
inserter.c:139: warning: implicit declaration of function âmysql_initâ
inserter.c:144: warning: implicit declaration of function âmysql_real_connectâ
inserter.c:144: error: âCLIENT_MULTI_STATEMENTSâ undeclared (first use in this function)
inserter.c:146: warning: implicit declaration of function âsprintfâ
inserter.c:146: warning: incompatible implicit declaration of built-in function âsprintfâ
inserter.c:146: warning: implicit declaration of function âmysql_errorâ
inserter.c:146: warning: format â%sâ expects type âchar *â, but argument 3 has type âintâ
inserter.c:153: warning: implicit declaration of function âneb_register_callbackâ
inserter.c:153: error: âNEBCALLBACK_TIMED_EVENT_DATAâ undeclared (first use in this function)
inserter.c: In function ânebmodule_deinitâ:
inserter.c:164: warning: implicit declaration of function âdeschedule_eventâ
inserter.c:164: error: âEVENT_USER_FUNCTIONâ undeclared (first use in this function)
inserter.c:164: error: âTRUEâ undeclared (first use in this function)
inserter.c:166: error: âNSLOG_INFO_MESSAGEâ undeclared (first use in this function)
inserter.c:168: warning: implicit declaration of function âmysql_closeâ
inserter.c:170: warning: implicit declaration of function âneb_deregister_callbackâ
inserter.c:170: error: âNEBCALLBACK_HOST_STATUS_DATAâ undeclared (first use in this function)
inserter.c:171: error: âNEBCALLBACK_SERVICE_STATUS_DATAâ undeclared (first use in this function)
inserter.c:172: error: âNEBCALLBACK_HOST_CHECK_DATAâ undeclared (first use in this function)
inserter.c:173: error: âNEBCALLBACK_SERVICE_CHECK_DATAâ undeclared (first use in this function)
inserter.c: In function âloadconfigâ:
inserter.c:181: error: âhostâ undeclared (first use in this function)
inserter.c:181: error: âhlâ undeclared (first use in this function)
inserter.c:182: error: âserviceâ undeclared (first use in this function)
inserter.c:182: error: âslâ undeclared (first use in this function)
inserter.c:183: error: âhostgroupâ undeclared (first use in this function)
inserter.c:183: error: âhgâ undeclared (first use in this function)
inserter.c:184: error: âservicegroupâ undeclared (first use in this function)
inserter.c:184: error: âsgâ undeclared (first use in this function)
inserter.c:190: error: âNEBCALLBACK_TIMED_EVENT_DATAâ undeclared (first use in this function)
inserter.c:193: error: ânebstruct_timed_event_dataâ undeclared (first use in this function)
inserter.c:193: error: syntax error before â)â token
inserter.c:193: error: âNEBTYPE_TIMEDEVENT_ADDâ undeclared (first use in this function)
inserter.c:198: warning: implicit declaration of function âasprintfâ
inserter.c:255: warning: value computed is not used
inserter.c:258: error: ânebstruct_host_status_dataâ undeclared (first use in this function)
inserter.c:258: error: syntax error before âdsâ
inserter.c:259: error: âdsâ undeclared (first use in this function)
inserter.c:263: error: âNEBCALLBACK_HOST_STATUS_DATAâ undeclared (first use in this function)
inserter.c:268: warning: incompatible implicit declaration of built-in function âsprintfâ
inserter.c:269: error: âNSLOG_INFO_MESSAGEâ undeclared (first use in this function)
inserter.c:269: error: âTRUEâ undeclared (first use in this function)
inserter.c:271: warning: value computed is not used
inserter.c:274: error: ânebstruct_service_status_dataâ undeclared (first use in this function)
inserter.c:274: error: syntax error before âdsâ
inserter.c:277: error: âNEBCALLBACK_SERVICE_STATUS_DATAâ undeclared (first use in this function)
inserter.c:292: warning: value computed is not used
inserter.c:294: error: âhostgroupmemberâ undeclared (first use in this function)
inserter.c:294: error: âhgmâ undeclared (first use in this function)
inserter.c:347: warning: value computed is not used
inserter.c:349: error: âservicegroupmemberâ undeclared (first use in this function)
inserter.c:349: error: âsgmâ undeclared (first use in this function)
inserter.c:431: error: âNEBCALLBACK_HOST_CHECK_DATAâ undeclared (first use in this function)
inserter.c:432: error: âNEBCALLBACK_SERVICE_CHECK_DATAâ undeclared (first use in this function)
inserter.c: In function âprocessCheckâ:
inserter.c:447: error: âNEBCALLBACK_HOST_CHECK_DATAâ undeclared (first use in this function)
inserter.c:449: error: ânebstruct_host_check_dataâ undeclared (first use in this function)
inserter.c:449: error: âhost_check_dataâ undeclared (first use in this function)
inserter.c:449: error: syntax error before â)â token
inserter.c:451: error: âNEBTYPE_HOSTCHECK_PROCESSEDâ undeclared (first use in this function)
inserter.c:466: error: âNEBCALLBACK_SERVICE_CHECK_DATAâ undeclared (first use in this function)
inserter.c:468: error: ânebstruct_service_check_dataâ undeclared (first use in this function)
inserter.c:468: error: âservice_check_dataâ undeclared (first use in this function)
inserter.c:468: error: syntax error before â)â token
inserter.c:470: error: âNEBTYPE_SERVICECHECK_PROCESSEDâ undeclared (first use in this function)
inserter.c:489: warning: incompatible implicit declaration of built-in function âsprintfâ
inserter.c:490: error: âNSLOG_INFO_MESSAGEâ undeclared (first use in this function)
inserter.c:490: error: âTRUEâ undeclared (first use in this function)
inserter.c: In function âprocessStatusâ:
inserter.c:502: error: âserviceâ undeclared (first use in this function)
inserter.c:502: error: âtmp_serviceâ undeclared (first use in this function)
inserter.c:503: error: âhostâ undeclared (first use in this function)
inserter.c:503: error: âtmp_hostâ undeclared (first use in this function)
inserter.c:509: error: âTRUEâ undeclared (first use in this function)
inserter.c:516: error: âNEBCALLBACK_HOST_STATUS_DATAâ undeclared (first use in this function)
inserter.c:518: error: ânebstruct_host_status_dataâ undeclared (first use in this function)
inserter.c:518: error: âhost_status_dataâ undeclared (first use in this function)
inserter.c:518: error: syntax error before â)â token
inserter.c:519: error: syntax error before â)â token
inserter.c:711: error: âNEBCALLBACK_SERVICE_STATUS_DATAâ undeclared (first use in this function)
inserter.c:713: error: ânebstruct_service_status_dataâ undeclared (first use in this function)
inserter.c:713: error: âservice_status_dataâ undeclared (first use in this function)
inserter.c:713: error: syntax error before â)â token
inserter.c:714: error: syntax error before â)â token
inserter.c:889: warning: incompatible implicit declaration of built-in function âsprintfâ
inserter.c:890: error: âNSLOG_INFO_MESSAGEâ undeclared (first use in this function)
inserter.c: In function âquerifyâ:
inserter.c:913: warning: implicit declaration of function âmysql_real_escape_stringâ
inserter.c: In function âappendâ:
inserter.c:947: error: âNSLOG_INFO_MESSAGEâ undeclared (first use in this function)
inserter.c:947: error: âTRUEâ undeclared (first use in this function)
inserter.c: In function âerr_outâ:
inserter.c:980: error: âNSLOG_INFO_MESSAGEâ undeclared (first use in this function)
inserter.c:980: error: âTRUEâ undeclared (first use in this function)
inserter.c: In function âsql_dumpâ:
inserter.c:1009: error: âTRUEâ undeclared (first use in this function)
inserter.c:1068: warning: implicit declaration of function âmysql_real_queryâ
inserter.c:1069: warning: implicit declaration of function âprintfâ
inserter.c:1069: warning: incompatible implicit declaration of built-in function âprintfâ
inserter.c:1069: warning: implicit declaration of function âmysql_errnoâ
inserter.c:1069: warning: format â%sâ expects type âchar *â, but argument 2 has type âintâ
make: *** [all] Error 1
User avatar
divagater
Cacti User
Posts: 191
Joined: Wed Nov 17, 2004 5:22 pm
Location: Chapel Hill, NC.
Contact:

Post by divagater »

You are missing the Nagios source and the MySQL development libraries. The inserter module needs to be compiled against the Nagios source.

1st, as per the README please verify that you have Nagios 2.0b4 & MySQL 4.1.x. You will also need the MySQL development package for the version of MySQL you are running. The development package has some required libraries.

NOTE: I just noticed Nagios 2.0b5 is out. As per the change log there were not any changes to the event broker API so this release will probably work fine but I have not tested it yet.

If you installed Nagios from a distribution CD then you prbably ony installed a pre-compiled Nagios. Who ever compiled Nagios may or may not have enabled the event broker which is needed.


The simplest way to get this going will be to download the Nagios src from nagios.org and compile it with --enable-event-broker and any other options you need for your environment.

Download Nagios 2.0b4 or greater
cd /path/to/nagios-src/
./configure --help
./configure --enable-event-broker --with-command-group=<some group>
make
make install <option>

(I like the default install paths but make sure they are what you want. You need the command group option if you want to issue Nagios commands from within NPC. you will create a group and add your httpd user to the group)

Once Nagios is built and installed, copy the inserter.c and makefile from npc/neb/ to /path/to/nagios-src/module. cd to /path/to/nagios-src/module and run make. Now copy inserter.o to /path/to/nagios/modules and set the config options in nagios.cfg that are outlined in the README.

Hope this helps,
Billy
Nemea
Posts: 13
Joined: Tue Nov 15, 2005 10:33 am

Post by Nemea »

Thank you for this Addon!
I tried to install it.

I use:

Debian 1:3.3.5-12
Linux version 2.6.8-2-686
gcc version 3.3.5

Cacti 0.8.6g
Nagios-CVS 14.11.2005
npc-0.1.1a
cacti-plugin-arch Version 0.6 (files-0.8.6g)

MySQL:
mysql Ver 12.22 Distrib 4.0.24, for pc-linux-gnu (i386)

libmysqlclient10-dev <---- wrong? 14-dev won't install

innodb:
mysql> SHOW VARIABLES LIKE '%innodb%';
+---------------------------------+------------------------+
| Variable_name | Value |
+---------------------------------+------------------------+
| have_innodb | YES |
| innodb_additional_mem_pool_size | 1048576 |
| innodb_autoextend_increment | 8 |
| innodb_buffer_pool_size | 8388608 |
| innodb_data_file_path | ibdata1:10M:autoextend |


inserter compile: ok, no error

nagios is installed in /opt/nagios

I found no directory called modules, so I created it
/opt/nagios/modules

inserter.o copied to this directory


nagios.cfg:
broker_module=/opt/nagios/modules/inserter.o


NPC:
On Cacti-Webinterface there is a new tab NPC after I enabled access to view under settings

The dropdownlist for "Nagios Host Mapping" only lists "none".

And how do I call the setup for creating the new mysql-dbs?
/cacti/plugins/npc/setup.php
only a white screen

I found this in /var/log/messages:

Nov 14 15:16:57 srvcacti nagios: Caught SIGTERM, shutting down...
Nov 14 15:16:57 srvcacti nagios: Successfully shutdown... (PID=2158)
Nov 14 15:17:10 srvcacti nagios: Nagios 2.0b4 starting... (PID=5153)
Nov 14 15:17:10 srvcacti nagios: LOG VERSION: 2.0
Nov 14 15:17:10 srvcacti nagios: Error: Could not load module '/opt/nagios/modules/inserter.o' -> /opt/nagios/modules/inserter.o: undefined symbol: compress


Any ideas?
User avatar
divagater
Cacti User
Posts: 191
Joined: Wed Nov 17, 2004 5:22 pm
Location: Chapel Hill, NC.
Contact:

Post by divagater »

/cacti/plugins/npc/setup.php is run by default anytime you load a Cacti page. Thats part of the plugin architecture so setup.php never needs to be run manually.

I am not entirely certain what the issue is but I suspect its a zlib issue. try modifying the makefile as follows. The make file is simple and consists of only 2 lines.

Change

gcc -g -O2 -Wall -o inserter.o inserter.c -shared -I../include -I/usr/include/mysql -lmysqlclient -fPIC

to

gcc -g -O2 -Wall -o inserter.o inserter.c -shared -I../include -I/usr/include/mysql -lmysqlclient -lz -fPIC

The only difference is that I added -lz after -lmysqlclient. I googled for this solution. Hope it helps you out.
Nemea
Posts: 13
Joined: Tue Nov 15, 2005 10:33 am

Post by Nemea »

Great!

I think it fixed my problem:

Nov 16 08:56:33 srvcacti nagios: Nagios 2.0b4 starting... (PID=2521)
Nov 16 08:56:33 srvcacti nagios: LOG VERSION: 2.0
Nov 16 08:56:33 srvcacti nagios: initializing nagios-db mysql inserter...
Nov 16 08:56:33 srvcacti nagios: nagios-db: inserter locked into db
Nov 16 08:56:33 srvcacti nagios: Event broker module '/opt/nagios/modules/inserter.o' initialized successfully.
Nov 16 08:56:33 srvcacti nagios: Finished daemonizing... (New PID=2523)
Nov 16 08:56:33 srvcacti nagios: Table 'cacti.npc_hostgroup_membership' doesn't exist 1146 delete from npc_hostgroup_membership
Nov 16 08:56:33 srvcacti nagios: nagios-db: inserter unloading...
Nov 16 08:56:33 srvcacti nagios: nagios-db: inserter unloading...
Nov 16 08:56:33 srvcacti nagios: nagios-db: inserter unloading...
Nov 16 08:56:33 srvcacti nagios: nagios-db: inserter unloading...
Nov 16 08:56:33 srvcacti nagios: nagios-db: inserter unloading...
Nov 16 08:56:33 srvcacti nagios: nagios-db: configured 5 hosts


Thx ... now I will visit Linux World in Frankfurt :)
User avatar
divagater
Cacti User
Posts: 191
Joined: Wed Nov 17, 2004 5:22 pm
Location: Chapel Hill, NC.
Contact:

Post by divagater »

I am glad that fix got the inserter module loaded. I don't like this line though:

Table 'cacti.npc_hostgroup_membership' doesn't exist 1146 delete from npc_hostgroup_membership

The first time you loaded NPC all the tables should have been created. Verify that you have the following tables in your cacti database:

npc_comment
npc_config_params
npc_flapping_host
npc_flapping_service
npc_host
npc_host_check
npc_host_history
npc_hostgroup
npc_hostgroup_membership
npc_service
npc_service_check
npc_service_history
npc_servicegroup
npc_servicegroup_membership

If you do not have all the tables listed its possible there is an sql error in setup.php.

If there is a table missing find the CREATE TABLE <table name> sql in setup.php. The full sql will be everything between the double quotes. Copy the sql and run it manually against the cacti db using your favorite mysql client. Send me any errors.

Cheers,
Billy
Nemea
Posts: 13
Joined: Tue Nov 15, 2005 10:33 am

Post by Nemea »

OK, all tables are missing in my cacti-db ;)


I tried it manually:

mysql>CREATE TABLE `npc_config_params` (`opt` char(64) NOT NULL default '',`value` int(11) default NULL,PRIMARY KEY (`opt`),UNIQUE KEY `opt` (`opt`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Nagios configuration data';



ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT CHARSET=latin1 COMMENT='Nagios configuration data'' at




mysql>CREATE TABLE `npc_flapping_host` (`id` int(11) NOT NULL default '0',PRIMARY KEY (`id`),CONSTRAINT `flapping_host_ibfk_1` FOREIGN KEY (`id`) REFERENCES `npc_host` (`id`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Flapping hosts';


ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT CHARSET=latin1 COMMENT='Flapping hosts'' at line 1


Something with innodb?
Or that I don't use MySQL 4.1 (mysql Ver 12.22 Distrib 4.0.24, for pc-linux-gnu (i386) )
tomkul
Posts: 10
Joined: Wed Nov 16, 2005 5:53 pm

Problem with innoDB

Post by tomkul »

I have this error:

Warning: mysql_query(): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=l in /var/www/html/cacti/plugins/npc/setup.php on line 394


rgrds
tko
User avatar
divagater
Cacti User
Posts: 191
Joined: Wed Nov 17, 2004 5:22 pm
Location: Chapel Hill, NC.
Contact:

Post by divagater »

I suspect for both of you its an issue with your MySQL version. I have only tested on MySQL 4.1 and there is some stuff I am doing with the inserter module that I believe requires 4.1 or greater. So as per the README MySQL 4.1.x is required.
tomkul
Posts: 10
Joined: Wed Nov 16, 2005 5:53 pm

Post by tomkul »

It seems to be a syntax error in this file
Removing ';' from ';,' does help

Seems that this error is not disastrous and my problem is rather how to stop displaying mysql-client errors/warnings on cacti pages after upgrading from 3.23 to 4.1.13

rgrds
tko
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests