Cacti / plugin_gexport

Cacti Graph Export Plugin
GNU General Public License v2.0
12 stars 9 forks source link

gexport php error (posix_kill) #31

Closed fristi737 closed 6 years ago

fristi737 commented 6 years ago

Hello Github members,

As asked by member netniV on Cacti forum: Running Cacti 1.1.31 on W2012 R2, we use the graph export utility, after a certain time (several days) the export stops and errors: All future exports end with the same error We run gexport 1.4.1

2018/08/03 14:58:04 - CMDPHP PHP ERROR NOTICE Backtrace: (C:\Apache24\htdocs\cacti\plugins\gexport\poller_export.php: 107 graph_export)(C:\Apache24\htdocs\cacti\plugins\gexport\functions.php: 120 run_export)(C:\Apache24\htdocs\cacti\plugins\gexport\functions.php: 145 posix_kill)(C:\Apache24\htdocs\cacti\lib\functions.php: 4812 CactiErrorHandler)(C:\Apache24\htdocs\cacti\lib\functions.php: 4480 cacti_debug_backtrace) 2018/08/03 14:58:04 - ERROR PHP NOTICE: Use of undefined constant SIGTERM - assumed 'SIGTERM' in file: C:\Apache24\htdocs\cacti\lib\functions.php on line: 4812

Kind regards, Lieven Stubbe Belgian railways

netniV commented 6 years ago

Your version is outdated but I will attempt to locate and find the issue. The chances are you don't have the posix-compatible functions enabled under windows.

netniV commented 6 years ago

I take that back, I mixed up the gexport and cacti versions when I read it. I'm looking into this further but I suspect that this is because we have used posix_kill to terminate an existing session which may not be available under windows.

netniV commented 6 years ago

I suspect you may have had other errors because this only occurs if it believes the export is already running. If you look at the graph_exports table it will have a pid next to the graph export. If it is non-zero that was what it believed to have started.

fristi737 commented 6 years ago

Hey netniV,

Thanks for reaching out so fast, what you are saying is correct, the export is already running several days before trowing the posix error. We ran Cacti for more than 10j on Solaris10 without any issue, but then the majority decided to migrate this to Windows :-(( We didn't really had any other errors, so don't understand what you mean by "other errors". There is however an SQL backtrace entry in the logs concerning the Gexport

image image

netniV commented 6 years ago

What was the backtrace?

fristi737 commented 6 years ago

the backtrace is included as image in my previous post (blue entry)

netniV commented 6 years ago

Oh that was so small I thought it was part of the other picture.

fristi737 commented 6 years ago

Hi netniV, Any news on the posix error, since yesterday Cacti gexport crashed again...

netniV commented 6 years ago

Could you post the backtrace as text? it's hurting my eyes squinting at the picture when I attempt to review it again.

netniV commented 6 years ago

Oh and can you do the following SQL:

select * from graph_exports
fristi737 commented 6 years ago

Hi netniV,

The crashes are happening mor often now

2018/09/13 11:15:42 - CMDPHP PHP ERROR NOTICE Backtrace: (C:\Apache24\htdocs\cacti\plugins\gexport\poller_export.php: 107 graph_export) (C:\Apache24\htdocs\cacti\plugins\gexport\functions.php: 120 run_export) (C:\Apache24\htdocs\cacti\plugins\gexport\functions.php: 145 posix_kill) (C:\Apache24\htdocs\cacti\lib\functions.php: 4812 CactiErrorHandler) (C:\Apache24\htdocs\cacti\lib\functions.php: 4480 cacti_debug_backtrace) 2018/09/13 11:15:42 - ERROR PHP NOTICE: Use of undefined constant SIGTERM - assumed 'SIGTERM' in file: C:\Apache24\htdocs\cacti\lib\functions.php on line: 4812

gexport.zip

netniV commented 6 years ago

OK, I believe that this is happening because the posix module is not enabled (presumably because it's windows). Unfortunately, there are quite a few places where posix is being used in the core and it's actually the core complaining, not gexport. SIGTERM is a posix-based constant.

fristi737 commented 6 years ago

It is Windows S2012 R2 So apparently posix doesn't exist on W and only in Windows S2016 there is some kind of WSL (windows subsystem for Linux). So there is no solution to this issue? We are the only one in the world running Cacti on W?

netniV commented 6 years ago

No, but testing needs to be done and fixes to make it work right. Most cacti systems are run on Linux and unfortunately, some of the code is developed but was not fully tested on a Windows platform (since most of us don't even run Cacti there). We are going to be doing a beta for 1.2, so I'm going to make an effort to try and resolve that.

How to fix your issue in the meantime is a curious one.

netniV commented 6 years ago

Try applying this patch:

diff --git a/lib/functions.php b/lib/functions.php
index e525151b..0c1efb39 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -4804,6 +4804,9 @@ function repair_system_data_input_methods($step = 'import') {
 }

 if ($config['cacti_server_os'] == 'win32' && !function_exists('posix_kill')) {
+       if (!defined('SIGTERM')) {
+               define('SIGTERM',9);
+       }
        function posix_kill($pid, $signal = SIGTERM) {
                $wmi   = new COM("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
                $procs = $wmi->ExecQuery("SELECT ProcessId FROM Win32_Process WHERE ProcessId='" . $pid . "'");
fristi737 commented 6 years ago

Hey netniV, I really like to test this, but i am not really a developper (network admin I am), do i need to include the 3 lines in green with a + before the line in the existing code?

netniV commented 6 years ago

Don't include the + as those are just markers to show additions. A - means removed.

fristi737 commented 6 years ago

Hey netniV, Deployed the patch and it seems to hold, keep you posted on any changes (read=posix crashes) Thx a lot for the effort, appreciate a lot!!