netniV / cisco-sfp

Cisco SFP Statistics for Cacti 1.x. This is to host code from the Cacti forums for others to use. I do not actively maintain this code, but welcome pull requests from others where they believe this can be improved. Cisco SFP Statistics for Cacti (c) 2007-2008 sodium in 2017
https://forums.cacti.net/viewtopic.php?f=19&t=23089 for others
GNU General Public License v2.0
8 stars 2 forks source link

Compatibility with PHP 7.x #1

Closed pyron83 closed 6 years ago

pyron83 commented 6 years ago

Hi,

I have a Debian 9 server with cacti 1.1.30.

I installed succesfully the template and created the graphs for optic interfaces I intend to monitor, but the graphs remain empty with "-nan" as value.

If I run the SNMP query by command-line, it works correctly and I get the correct values.

If you need any further data, I'm open to any request or debug.

thanks

netniV commented 6 years ago

@0xygen8 this script should still run on your test system. I thought we'd done it to work on both 0.8.x and 1.x, or am I confusing myself more.

pyron83 commented 6 years ago

with the last commit, I see something finally:

2018/01/30 16:23:20 - WEBLOG CACTI2RRD: /usr/bin/rrdtool graphv - --imgformat=PNG --start='1517239400' --end='1517325800' --pango-markup --title='myrouter cisco6500 SFP |query_device| - LACP_myrouter_otherrouter' --vertical-label='dBm' --slope-mode --base=1000 --height=120 --width=500 --tabwidth '30' --alt-autoscale COMMENT:"From 2018/01/29 16\:23\:20 To 2018/01/30 16\:23\:20\c" COMMENT:" \n" --border 1 --slope-mode --watermark 'Generated by Cacti®' DEF:a='/usr/share/cacti/site/rra/myrouter_cisco6500_sfp_rx_3812.rrd':'sfp_tx':AVERAGE DEF:b='/usr/share/cacti/site/rra/myrouter_cisco6500_sfp_rx_3812.rrd':'sfp_rx':AVERAGE LINE1:a#002A97FF:'OpticalTxPower' GPRINT:a:LAST:'Current\:%2.1lf' GPRINT:a:AVERAGE:'Average\:%2.1lf' GPRINT:a:MAX:'Maximum\:%2.1lf\n' LINE1:b#00CF00FF:'OpticalRxPower' GPRINT:b:LAST:'Current\:%2.1lf' GPRINT:b:AVERAGE:'Average\:%2.1lf' GPRINT:b:MAX:'Maximum\:%2.1lf\n' 

the graph it's still empty, but from what I understand this looks like an attempt to write some values into it

netniV commented 6 years ago

The above line is creating the graph. Did you see anything in the log for Failed to retrieve valid status ?

pyron83 commented 6 years ago

Nope really, I filtered the clog with that line and I didn't find anything.

Tomorrow I'll check again the logs.

Il 30/gen/2018 16:45, "netniV" notifications@github.com ha scritto:

The above line is creating the graph. Did you see anything in the log for Failed to retrieve valid status ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/netniV/cisco-sfp/issues/1#issuecomment-361634708, or mute the thread https://github.com/notifications/unsubscribe-auth/AhgxAKKPLO_yX4QDaHN3aSfc6C50NKGsks5tPzkBgaJpZM4RseMB .

netniV commented 6 years ago

I would try running it directly at the command line to make sure it's working properly for you.

pyron83 commented 6 years ago

I'm sorry but today I've been very busy and I didn't have much time to look at this issue.

Anyway if I run the script directly from the CLI, he doesn't show any error.

I added: error_reporting(E_ALL); ini_set('display_errors', '1') to the script.

And I get:

PHP Warning: Missing argument 1 for ss_sfp(), called in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 32 and defined in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 45

Warning: Missing argument 1 for ss_sfp(), called in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 32 and defined in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 45 PHP Warning: Missing argument 2 for ss_sfp(), called in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 32 and defined in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 45

Warning: Missing argument 2 for ss_sfp(), called in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 32 and defined in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 45 PHP Notice: Undefined variable: snmp_auth in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 46

Notice: Undefined variable: snmp_auth in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 46 PHP Notice: Undefined offset: 1 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 48

Notice: Undefined offset: 1 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 48 PHP Notice: Undefined offset: 2 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 49

Notice: Undefined offset: 2 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 49 PHP Notice: Undefined offset: 3 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 50

Notice: Undefined offset: 3 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 50 PHP Notice: Undefined offset: 4 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 51

Notice: Undefined offset: 4 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 51 PHP Notice: Undefined offset: 5 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 52

Notice: Undefined offset: 5 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 52 PHP Notice: Undefined offset: 6 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 53

Notice: Undefined offset: 6 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 53 PHP Notice: Undefined offset: 7 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 71

Notice: Undefined offset: 7 in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 71 PHP Notice: Undefined variable: cmd in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 89

Notice: Undefined variable: cmd in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 89 PHP Notice: Undefined variable: cmd in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 105

Notice: Undefined variable: cmd in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 105 PHP Notice: Undefined variable: cmd in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 249

Notice: Undefined variable: cmd in /usr/share/cacti/site/scripts/ss_65xx_sfp.php on line 249

but it seems all normal to me, they should be values that the script gets from Cacti.

For now the graphs are still empty, maybe tomorrow or this afternoon I'll investigate further.

netniV commented 6 years ago

Now that is strange because that does not marry up to my local copy of the ss_65xx_sfp.php. Which version are you using?

netniV commented 6 years ago

Forget that, just realised the line numbers will all be offset by two.

netniV commented 6 years ago

Try doing this next:

php -q script_server.php

When that starts up, paste in

/usr/share/cacti/site/scripts/ss_65xx_sfp.php ss_sfp 'myrouter.mydomain:176:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1026'

Then you can exit using:

quit
pyron83 commented 6 years ago

Did that right now, I get "U"

netniV commented 6 years ago

I think I may have just spotted what the issue might be. The cacti_snmp_get() call had a MAX_OIDS parameter on it but that isn't in the function parameters list so seems to be erroneous.

Try the latest commit https://github.com/netniV/cisco-sfp/commit/1c63f6fbcc02516207aba4038f8f075b0a3e819d

pyron83 commented 6 years ago

I got your last commit, and I did the "php -q" stuff to see if there is any difference.

Now i get:

php -q /usr/share/cacti/site/script_server.php PHP Script Server has Started - Parent is cmd /usr/share/cacti/site/scripts/ss_65xx_sfp.php ss_sfp 'myrouter.mydomain:176:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1026 -40

netniV commented 6 years ago

OK that means the walk failed. Can you check the cacti log?

pyron83 commented 6 years ago

2018/01/31 15:52:01 - PHPSVR WARNING: Script Server terminated with signal '2' in file:'ss_65xx_sfp.php', function:'ss_sfp', params:''myrouter:176:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1026'[D[D[D[D[D[D[D[D[D[D[D[D[D[D[D[D[D[D' 2018/01/31 15:51:44 - PHPSVR DEBUG: PID[3629] CTR[0] INC: 'ss_65xx_sfp.php' FUNC: 'ss_sfp' PARMS: ''myrouter:176:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1026'[D[D[D[D[D[D[D[D[D[D[D[D[D[D[D[D[D[D' 2018/01/31 15:51:32 - PHPSVR WARNING: Script Server terminated with signal '2' in file:'ss_65xx_sfp.php', function:'ss_sfp', params:''myrouter:176:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1

I've to be careful because I have Cisco 6500 and it's easy to mix the 2... maybe I could as well disable the template on 1 of the 2 until we fix the issue

pyron83 commented 6 years ago

update: ok I deleted the graphs of 1 of the 2 Cisco 6500, so I can't mix the 2 in the next debug sessions.

netniV commented 6 years ago

There seems to be a lot of extra characters there.

netniV commented 6 years ago

In addition to the [D's which seem to be erroneous, there is also the signal '2' (SIGINT) which basically means that the script server was terminated by another process (or even PHP). One thing I would like to see better in the parameters list is the way it lists them.

Edit script_server.php and look for the call to parseArgs(). The following cacti_log statement can be changed to:

cacti_log("DEBUG: PID[$pid] CTR[$ctr] INC: '". basename($include_file) .
        "' FUNC: '$function' PARMS: '" . implode('\', \'',$parameters) .
        "'", false, 'PHPSVR', POLLER_VERBOSITY_DEBUG);

This will output the array value and arguments in the style that is used by the functions. Hopefully, that will give us a truer understanding of what's being used.

pyron83 commented 6 years ago

I inserted yesterday those lines in script-server.php

today we'll see the result

netniV commented 6 years ago

There is a problem with the above code. The $paramteres should have been $parameter_array.

Not sure about the file you mentioned though.

pyron83 commented 6 years ago

wrong copy & paste LOL

I'm going to update the code with the fix you mentioned.

netniV commented 6 years ago

Cool. Just to be clear it should be

cacti_log("DEBUG: PID[$pid] CTR[$ctr] INC: '". basename($include_file) .
        "' FUNC: '$function' PARMS: '" . implode('\', \'',$parameter_array) .
        "'", false, 'PHPSVR', POLLER_VERBOSITY_DEBUG);
pyron83 commented 6 years ago

log level = debug selective debug ID = 5 (1 of the 2 cisco 6500 - myrouter1 in the logs)

pyron83 commented 6 years ago

i'm keeping an eye on the CLOG from 1 hour.

I don't see any entry in errors, warning, or debug

the only entries are about values and they are always 'U'

pyron83 commented 6 years ago

There is something I don't understand about the script.

If I do an snmpwalk to get -dbm values I do:

snmpwalk -v2c -cMYCOMMUNITY MYROUTER 1.3.6.1.4.1.9.9.91.1.1.1.1.4
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.12 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.18 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.19 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.20 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.21 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.22 = INTEGER: 220
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.29 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.30 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.31 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.32 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.33 = INTEGER: 220
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.38 = INTEGER: 3
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.39 = INTEGER: 2
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.42 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.43 = INTEGER: 33
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.46 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.47 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.50 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.51 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.54 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.55 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.58 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.59 = INTEGER: 2
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1002 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1003 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1004 = INTEGER: 28
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1005 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1006 = INTEGER: 24
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1007 = INTEGER: 30
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1060 = INTEGER: 262
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1061 = INTEGER: 32
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1062 = INTEGER: 121
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1063 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1064 = INTEGER: -152
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1276 = INTEGER: 258
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1277 = INTEGER: 32
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1278 = INTEGER: 23
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1279 = INTEGER: -65
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1280 = INTEGER: -62
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1288 = INTEGER: 266
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1289 = INTEGER: 32
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1290 = INTEGER: 23
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1291 = INTEGER: -63
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1292 = INTEGER: -72
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.2001 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.2002 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.2003 = INTEGER: 25
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.2004 = INTEGER: 25
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3002 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3003 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3004 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3005 = INTEGER: 31
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3006 = INTEGER: 24
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3007 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3008 = INTEGER: 30
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3009 = INTEGER: 51
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3010 = INTEGER: 35
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3011 = INTEGER: 47
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3015 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3016 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3019 = INTEGER: 28
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.3020 = INTEGER: 23
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4002 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4003 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4004 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4005 = INTEGER: 33
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4006 = INTEGER: 23
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4007 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4008 = INTEGER: 30
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4009 = INTEGER: 52
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4010 = INTEGER: 35
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4011 = INTEGER: 47
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4015 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4016 = INTEGER: 26
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4019 = INTEGER: 28
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.4020 = INTEGER: 23

of those the only good ones are:

snmpwalk -v2c -cMYCOMMUNITY MYROUTER 1.3.6.1.2.1.47.1.1.1.1.2 | grep "Power Sensor"
SNMPv2-SMI::mib-2.47.1.1.1.1.2.1063 = STRING: "GigabitEthernet1/5 Transmit Power Sensor"
SNMPv2-SMI::mib-2.47.1.1.1.1.2.1064 = STRING: "GigabitEthernet1/5 Receive Power Sensor"
SNMPv2-SMI::mib-2.47.1.1.1.1.2.1279 = STRING: "GigabitEthernet1/23 Transmit Power Sensor"
SNMPv2-SMI::mib-2.47.1.1.1.1.2.1280 = STRING: "GigabitEthernet1/23 Receive Power Sensor"
SNMPv2-SMI::mib-2.47.1.1.1.1.2.1291 = STRING: "GigabitEthernet1/24 Transmit Power Sensor"
SNMPv2-SMI::mib-2.47.1.1.1.1.2.1292 = STRING: "GigabitEthernet1/24 Receive Power Sensor"
sh interfaces transceiver detail 
mA: milliamperes, dBm: decibels (milliwatts), NA or N/A: not applicable.
++ : high alarm, +  : high warning, -  : low warning, -- : low alarm.
A2D readouts (if they differ), are reported in parentheses.
The threshold values are calibrated.

                            High Alarm  High Warn  Low Warn   Low Alarm
           Temperature         Threshold   Threshold  Threshold  Threshold
Port       (Celsius)          (Celsius)   (Celsius)  (Celsius)  (Celsius)
Gi1/5        26.2                95.5        90.5        -9.4      -44.4
Gi1/23       25.8                89.0        85.0        -5.0       -9.0
Gi1/24       26.6                89.0        85.0        -5.0       -9.0

                            High Alarm  High Warn  Low Warn   Low Alarm
            Voltage            Threshold   Threshold  Threshold  Threshold
Port        (Volts)            (Volts)     (Volts)    (Volts)    (Volts)
Gi1/5       3.23                  4.00        3.60        3.00       0.00
Gi1/23      3.27                  3.60        3.50        3.10       3.00
Gi1/24      3.26                  3.60        3.50        3.10       3.00

                            High Alarm  High Warn  Low Warn   Low Alarm
            Current            Threshold   Threshold  Threshold  Threshold
Port        (milliamperes)     (mA)        (mA)       (mA)       (mA)---
Gi1/5        12.1                70.0        60.0         0.0        0.0
Gi1/23        2.3                15.0        10.0         1.0        0.0
Gi1/24        2.3                15.0        10.0         1.0        0.0

            Optical            High Alarm  High Warn  Low Warn   Low Alarm
            Transmit Power     Threshold   Threshold  Threshold  Threshold
Port        (dBm)              (dBm)       (dBm)      (dBm)      (dBm)
Gi1/5         2.6                 8.0         6.0        -1.0       -3.0
Gi1/23       -6.4                 1.0        -3.0        -9.5      -13.5
Gi1/24       -6.3                 1.0        -3.0        -9.5      -13.5

            Optical            High Alarm  High Warn  Low Warn   Low Alarm
            Receive Power      Threshold   Threshold  Threshold  Threshold
Port        (dBm)              (dBm)       (dBm)      (dBm)      (dBm)
Gi1/5       -15.3                 0.0         0.0       -40.0      -40.0
Gi1/23       -6.2                 3.9         0.0       -17.0      -21.0
Gi1/24       -7.2                 3.9         0.0       -17.0      -21.0
snmpwalk -v2c -cMYCOMMYNITY MYROUTER 1.3.6.1.4.1.9.9.91.1.1.1.1.4.1063
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1063 = INTEGER: 26
snmpwalk -v2c-cMYCOMMYNITY MYROUTER 1.3.6.1.4.1.9.9.91.1.1.1.1.4.1064
SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1064 = INTEGER: -152

so the script does:

2018/02/01 11:05:30 - POLLER: Poller[1] Device[MYROUTER cisco6500] Graphs[MYROUTER cisco6500 SFP |query_device| - |query_descr|, MYROUTER cisco6500 SFP |query_device| - |query_descr|] DS[3868] CMD: /usr/share/cacti/site/scripts/ss_65xx_sfp.php 'MYROUTER.MYDOMAIN:5:2:161:5000:1:10:MYCOMMUNITY::::::' 'get' 'rx' '1063', output: U

why he doesn't get the value? I can't understand which kind of snmpget it's trying to do.

netniV commented 6 years ago

Slight deviation but here's a formatting tip, use three backticks ` to preformat output from logs, etc. It makes it easier to read and you can see how by editing your previous post. :)

Good link for what's available with markup: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet


Now, I went to test this with the script server by copying and pasting the command line you had used. I got the result 'U' and no warning about the fact that the include file was wrong. That was because my script file wasn't actually at the same place as yours.

You: /usr/share/cacti/site/scripts/ss_65xx_sfp.php
 Me: /usr/share/cacti/develop/scripts/ss_65xx_sfp.php

Until I put in the correct path I was constantly getting 'U'. Can you verify that the script is definitely at that location and check the group is readable by the website/poller user?

pyron83 commented 6 years ago

thanks for the formatting tip

BTW I checked and everything looks fine: -rwxr-xr-x 1 www-data www-data 12K Feb 1 10:01 /usr/share/cacti/site/scripts/ss_65xx_sfp.php (www-data is the user running Apache and so also Cacti)

also Cacti it's calling the script from the correct path:

2018/02/01 13:25:30 - POLLER: Poller[1] Device[MYROUTER cisco6500] Graphs[MYROUTER cisco6500 SFP |query_device| - |query_descr|, MYROUTER cisco6500 SFP |query_device| - |query_descr|] DS[3868] CMD: /usr/share/cacti/site/scripts/ss_65xx_sfp.php 'MYROUTER.MYDOMAIN:5:2:161:5000:1:10:MYCOMMUNITY::::::' 'get' 'rx' '1063', output: U
netniV commented 6 years ago

Well, time to give you some mods for the poller itself then to work out which section is giving you that 'U'. I presume you had the same thing when you manually ran the script server?

pyron83 commented 6 years ago

1) yep, always U, even we ran from bash

2) If I have to modify the poller itself, I believe it's time for me to create a second Cacti testing environment.

Until now, we modded stuff that didn't had any real impact on the production stuff (the only one being the script_server.php, but it was easy to go back to the original code).

Maybe I should try to create a second cacti instance next week.

netniV commented 6 years ago

Looking at the script server code, we will always get a 'U' if the function does not exist. That shouldn't happen unless something really weird is occurring. Otherwise, it should be the result from our script.

My next recommendation is to:

This will help determine which way the script server is going. If it appears to be in else section, this would suggest it isn't finding our function. If it is in the function_exists section of test_server.php, then we should modify the "get" case to output some extra debug information in ss_65xx_sfp.php

netniV commented 6 years ago

@pyron83 Just checking in with you to see if you have managed to have time to try the above?

pyron83 commented 6 years ago

Nope, I'm out of office for an installation.

I think I'll do that on Monday.

Thanks

-- Andrea Turbiglio

Il 02 feb 2018 12:29, "netniV" notifications@github.com ha scritto:

@pyron83 https://github.com/pyron83 Just checking in with you to see if you have managed to have time to try the above?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/netniV/cisco-sfp/issues/1#issuecomment-362561986, or mute the thread https://github.com/notifications/unsubscribe-auth/AhgxAJ11WX5kYHl9ItRBACrTZ6C07NrEks5tQvGBgaJpZM4RseMB .

netniV commented 6 years ago

OK, I'll check back late Monday then :)

pyron83 commented 6 years ago

I found and modified a total of 7 fputs is it correct?

like this:

cat /usr/share/cacti/site/test_server.php | grep fputs fputs(STDOUT, 'PHP Script Server has Started - Parent is ' . $environ . "4\n"); fputs(STDOUT, 'PHP Script Server Shutdown request received, exiting5\n'); fputs(STDOUT, "6U\n"); fputs(STDOUT, trim($result) . "1\n"); fputs(STDOUT, "2U\n"); fputs(STDOUT, "ERROR: Input Expected, Script Server Terminating3\n");

Later I'll try to run the script.

netniV commented 6 years ago

Yeah that'll do. After all it's a test script only you will see the output.

pyron83 commented 6 years ago

/usr/share/cacti/site/scripts/ss_65xx_sfp.php 'myrouter:5:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1063' 2U

netniV commented 6 years ago

OK, so can you post the code around where 2U is output?

pyron83 commented 6 years ago
else {
                                cacti_log("WARNING: Function does not exist  INC: '". basename($include_file) . "' FUNC: '" .$function . "' PARMS: '" . $parameters . "'", false, 'PHPSVR');
                                fputs(STDOUT, "2U\n");
                                fflush(STDOUT);
                        }
                }
netniV commented 6 years ago

Right, so what this is saying is that the function that we are trying to call does not exist. Now, that happens for one of two reason. First, we didn't manage to include the file properly, or second we are trying to find the wrong function.

Change that fputs to

fputs(STDOUT, "2U $include_file :: $function\n");

Let me know the output again. We are getting close now 👍

pyron83 commented 6 years ago

Done.

PHP Script Server has Started - Parent is cmd4 /usr/share/cacti/site/scripts/ss_65xx_sfp.php 'myrouter:5:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1063' 2U /usr/share/cacti/site/scripts/ss_65xx_sfp.php :: 'myrouter:5:2:161:5000:1:10:mycommunity::::::'

netniV commented 6 years ago

OK ... wait I just realised that no function name has been provided. It should be:

/usr/share/cacti/site/scripts/ss_65xx_sfp.php ss_sfp 'myrouter:5:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1063'

Can you edit the template and change the type from Script Data (Indexed) To Script Server Data (Indexed)?

pyron83 commented 6 years ago

1) > from Script Data (Indexed) To Script Server Data (Indexed)

it was already Script Server Data (Indexed)

2)


 # php -q /usr/share/cacti/site/test_server.php 
PHP Script Server has Started - Parent is cmd4
/usr/share/cacti/site/scripts/ss_65xx_sfp.php ss_sfp 'myrouter:5:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1063'
-15.21
netniV commented 6 years ago

Yes, that's what I would expect from the output. The curious thing is why the script server isn't providing the function name or finding the function when run from the poller. Have you rebuilt your poller cache? Does it list the function name in the command line like you just had there.

It's times like this I wish there was a way to tap in and query/test the server myself as it's leaving me a bit puzzled as to what's occurring.

pyron83 commented 6 years ago

Have you rebuilt your poller output?

Nope :\ not recently

Does it list the function name in the command line like you just had there.

sorry is this a question?

netniV commented 6 years ago

Yes, when you rebuild your poller cache, view it and see if it has the ss_sfp after the .php

pyron83 commented 6 years ago

Cacti says "Alternatively, if you are having problems with a specific Device, simply re-save that Device to rebuild its Poller Cache"

Maybe I'll do that later.

netniV commented 6 years ago

That's another way. It just seems that your cache is wrong.

pyron83 commented 6 years ago

I was looking at the logs, Cacti itself does a little different query from the one you suggested above:

cacti logs:

php -q /usr/share/cacti/site/test_server.php 
PHP Script Server has Started - Parent is cmd4
/usr/share/cacti/site/scripts/ss_65xx_sfp.php 'myrouter:5:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1063'
2U

your:

php -q /usr/share/cacti/site/test_server.php 
PHP Script Server has Started - Parent is cmd4
/usr/share/cacti/site/scripts/ss_65xx_sfp.php ss_sfp 'myrouter:5:2:161:5000:1:10:mycommunity::::::' 'get' 'rx' '1063'
-15.21

why is there that addictional "ss_sfp" in the middle that Cacti doesn't use?

netniV commented 6 years ago

Yeah, what I am trying to work out is why you are not getting the function name ss_sfp. That should be there.

pyron83 commented 6 years ago

I can rebuild the poller-cache if you like, that shouldn't have any impact on the Cacti server itself, I just remember that it takes some time to complete.

-- Andrea Turbiglio

2018-02-08 10:17 GMT+01:00 netniV notifications@github.com:

Yeah, what I am trying to work out is why you are not getting the function name. That should be there.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/netniV/cisco-sfp/issues/1#issuecomment-364049856, or mute the thread https://github.com/notifications/unsubscribe-auth/AhgxAKNMbxsC621i1Sd0gs-VKf8SAgSHks5tSrvAgaJpZM4RseMB .

netniV commented 6 years ago

OK, so when you edit the data query, you should see it say <path_cacti>/resource/script_server/cisco_sfp.xml and when you look at that file.

image

If you look at the top of the xml file, it should show:

        <name>Get Cisco SFP Statistics</name>
        <description>Get Cisco SFP Statistics</description>
        <script_path>|path_cacti|/scripts/ss_65xx_sfp.php</script_path>
        <script_function>ss_sfp</script_function>
        <script_server>php</script_server>
        <arg_prepend>|host_hostname|:|host_id|:|host_snmp_version|:|host_snmp_port|:|host_snmp_timeout|:|host_ping_retries|:|host_max_oids|:|host_snmp_community|:|host_snmp_username|:|host_snmp_password|:|host_snmp_context|:|host_snmp_auth_protocol|:|host_snmp_priv_passphrase|:|host_snmp_priv_protocol|</arg_prepend>