Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Wed May 24, 2017 2:43 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Plugin Development
PostPosted: Fri Dec 09, 2011 1:39 am 
Offline

Joined: Fri Dec 09, 2011 1:21 am
Posts: 8
Hi All,

I am developing a new cacti plug-in. The plug-in will fetch the information from a transporter table and process the data and insert into our custom table at regular intervals.
My method will fetch the information from the source table and sleep for 5 minutes and go back fetch ,insert and its in a loop.

Question :
1. I invoked the method in check _config part and the code is below..
function plugin_das_check_config () {
if(read_config_option('kpip_enable') == 'on') {
calculateTimeStampp(read_config_option('polling_interval'));
}
return true;
}

This makes the enable button to active and not showing the disabling icon. since i have used sleep($polling_interval) method.

2. Instead, can we use any hook ? i have used poller_bottom,Output and called the method. The method is not invoked.

Kindly provide your suggestion on this .
It would be really helpful.

Thanks.

Das.


Top
 Profile  
 
 Post subject: Re: Plugin Development
PostPosted: Fri Dec 09, 2011 8:25 am 
Offline
Developer
User avatar

Joined: Tue May 14, 2002 5:08 pm
Posts: 14863
Location: MI, USA
There are dozens of plugin examples at http://docs.cacti.net. Generally, if you want to do something immediately after the poller finishes, you use poller_bottom. Three good examples of intercepting the data as it's coming in are:

DSStats - Data Source Statistics (Much like Transporter)
THold - Threshold and Alarming
WeatherMap - Cacti Uber Tool

TheWitness

_________________
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
Gandalfs Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: Re: Plugin Development
PostPosted: Fri Dec 09, 2011 8:35 am 
Offline

Joined: Fri Dec 09, 2011 1:21 am
Posts: 8
Thanks for the reply.
Can we use sleep method for implementing the polling intervals ?

Or only cron tab is the option ..?


Thanks.

Regards,
G. Karuppiah Das


Top
 Profile  
 
 Post subject: Re: Plugin Development
PostPosted: Fri Dec 09, 2011 8:41 am 
Offline
Developer
User avatar

Joined: Tue May 14, 2002 5:08 pm
Posts: 14863
Location: MI, USA
I attempted to run PHP as a daemon years ago and the Cacti server would crash every fifth day. That was almost 8 years ago and a very old version of PHP. These days, many commercial entities use PHP in daemon mode w/o issues. However, we have found that using something that is not stateful is much safer as there are so many PHP versions floating around. Not using cron would have led to the collapse of the Cacti project years ago as this is a pure volunteer project and we all have day jobs. This is why we do things in cron.

For your part, you can do anything you want. In my day job, I do Cacti 'all the time' and there are daemons all over the place doing interesting things, but Cacti itself is still running in Cron.

TheWitness

_________________
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
Gandalfs Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: Re: Plugin Development
PostPosted: Fri Dec 09, 2011 8:51 am 
Offline

Joined: Fri Dec 09, 2011 1:21 am
Posts: 8
Thanks again for the response.

My problem with sleep, when i click the enable part of the plug-in the method fetch ,process, insert into custom table and goes to sleep so on....
With this,I am not getting the disable icon in the Action column of Plugin Management.

Even though my plug-in does the required thing, it does not allow the user to disable

Do you have any suggestion on this?

Regards
Das


Top
 Profile  
 
 Post subject: Re: Plugin Development
PostPosted: Fri Dec 09, 2011 8:56 am 
Offline
Developer
User avatar

Joined: Tue May 14, 2002 5:08 pm
Posts: 14863
Location: MI, USA
There is a second option on the 'read_config_option' to reread the active status from the database instead of the stored value. Use that in your plugin and you can exit or not start if the user disables the plugin.

TheWitness

_________________
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
Gandalfs Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: Re: Plugin Development
PostPosted: Wed Dec 14, 2011 7:09 am 
Offline

Joined: Fri Dec 09, 2011 1:21 am
Posts: 8
I have planned to execute the sleep method in a background process. Below is my code.
Code:
$extra_args = "-q " . $config["base_path"] . "/plugins/testing1/poll.php >> 2>&1 ";
exec_background($command_string, $extra_args);

poll.php file:
#!/usr/bin/php -q
<?php

echo " Hello wordl";
cacti_log(" Hellow World ",TRUE,TESTING1);


?>

Just updating the log.
The code in poll.php is not getting executed.

Is there anything wrong?

Thanks.

Regards,
Das


Top
 Profile  
 
 Post subject: Re: Plugin Development
PostPosted: Thu Dec 15, 2011 12:48 am 
Offline
Developer

Joined: Thu Apr 07, 2005 3:29 pm
Posts: 2534
Location: B/CS Texas
Can we backup a few steps and go back over exactly what you are trying to accomplish? From what I have read, it seems more like you should just use the poller_bottom hook that runs at the end of the poller (or poller_top if you want it before or on a more precise schedule). From there, you can run any function from your code that you like. Since the poller runs on an automated Cron, you can get a 5 minute interval pretty easily.

_________________
CactiEZ CD


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group