Custom script no longer runs on new Devices since upgrade

Templates, scripts for templates, scripts and requests for templates.

Moderators: Moderators, Developers

Post Reply
Author
Message
kevandju
Posts: 44
Joined: Tue Oct 10, 2006 3:30 pm

Custom script no longer runs on new Devices since upgrade

#1 Post by kevandju » Fri Mar 01, 2019 5:56 pm

Was on v0.8.8 something forever and then went to v1.1.37 and recently to v1.2.2. Ever since I left v0.8.8 a PHP script I have to count modems connected to a device no longer works. It continues to work on devices that I added under old version but doesn't return any data on new devices I've added since being on the 1.x.x platform. I've tried to run my script from the command line as well and confirmed it to give me zero results. No clue what I'm missing. Code is below. Can anyone offer me some ideas or things to try?

Code: Select all

<?php

/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
	die("<br><strong>This script is only meant to run at the command line.</strong>");
}

$no_http_headers = true;

/* display No errors */
error_reporting(0);

include_once(dirname(__FILE__) . "/../lib/snmp.php");

if (!isset($called_by_script_server)) {
	include_once(dirname(__FILE__) . "/../include/global.php");

	array_shift($_SERVER["argv"]);

	print call_user_func_array("ss_docsis_cmts_cm_count", $_SERVER["argv"]);
}

function ss_docsis_cmts_cm_count($hostname, $snmp_community, $snmp_version, $snmp_port, $snmp_timeout)
{
	$snmp_auth_username   = "";
	$snmp_auth_password   = "";
	$snmp_auth_protocol   = "";
	$snmp_priv_passphrase = "";
	$snmp_priv_protocol   = "";
	$snmp_context         = "";
	$oid				  = ".1.3.6.1.2.1.10.127.1.3.3.1.9"; //docsIfCmtsCmStatusValue

 	$other = 0;
 	$ranging = 0;
 	$rangingAborted = 0;
 	$rangingComplete = 0;
  	$ipComplete = 0;
  	$registrationComplete = 0;
  	$accessDenied = 0;

	$cms = reindex(cacti_snmp_walk($hostname, $snmp_community, $oid, $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER));

	//print_r($cms);

	$totals = array_count_values($cms);

	/*Fields defined in docsIfCmtsCmStatusValue */
	for ($i=0;($i<sizeof($totals));$i++) {
		$row = each($totals);
		if ($row["key"] == 1)
			$other = $row["value"];
		elseif ($row["key"] == 2)
			$ranging = $row["value"];
		elseif ($row["key"] == 3)
 			$rangingAborted = $row["value"];
		elseif ($row["key"] == 4)
 			$rangingComplete = $row["value"];
		elseif ($row["key"] == 5)
 			$ipComplete = $row["value"];
		elseif ($row["key"] == 6)
 			$registrationComplete = $row["value"];
		elseif ($row["key"] == 7)
 			$accessDenied = $row["value"];
	}

	return "other:$other " . "ranging:$ranging " . "rangingAborted:$rangingAborted " . "rangingComplete:$rangingComplete " . "ipComplete:$ipComplete " .	"registrationComplete:$registrationComplete " . "accessDenied:$accessDenied";
}

function reindex($arr) {
	$return_arr = array();

	for ($i=0;($i<sizeof($arr));$i++) {
		$return_arr[$i] = $arr[$i]["value"];
	}

	return $return_arr;
}

netniV
Cacti Guru User
Posts: 3018
Joined: Sun Aug 27, 2017 12:05 am

Re: Custom script no longer runs on new Devices since upgrad

#2 Post by netniV » Fri Mar 01, 2019 6:17 pm

Look at the Poller Cache (utilities) and find the command being used, then run that at the command line and see what output you get. Also, compare your script with others in the scripts folder. finally, make sure the definition is correct in the Data Input Methods.

kevandju
Posts: 44
Joined: Tue Oct 10, 2006 3:30 pm

Re: Custom script no longer runs on new Devices since upgrad

#3 Post by kevandju » Fri Mar 01, 2019 6:36 pm

When I run from command line on device that is graphing properly I still don't get results

Code: Select all

 php /var/www/html/cacti/scripts/ss_modem_count.php ss_docsis_cmts_cm_count 'vm.domain.com' 'mycommunity' '1' '161' '500'
other:0 ranging:0 rangingAborted:0 rangingComplete:0 ipComplete:0 registrationComplete:0 accessDenied:0
Last edited by kevandju on Fri Mar 01, 2019 7:01 pm, edited 1 time in total.

kevandju
Posts: 44
Joined: Tue Oct 10, 2006 3:30 pm

Re: Custom script no longer runs on new Devices since upgrad

#4 Post by kevandju » Fri Mar 01, 2019 7:01 pm

I'm comparing to other scripts and it looks good from what I can best tell. Data input methods look good too

<path_cacti>/scripts/ss_modem_count.php ss_docsis_cmts_cm_count <hostname> <snmp_community> <snmp_version> <snmp_port> <snmp_timeout>

Anything else I can check? Any reason that me running the exact command that is working for Cacti doesn't work for me at command line?


kevandju
Posts: 44
Joined: Tue Oct 10, 2006 3:30 pm

Re: Custom script no longer runs on new Devices since upgrad

#6 Post by kevandju » Sat Mar 02, 2019 11:18 am

This is what poller cache says

Code: Select all

Script Server: /var/www/html/cacti/scripts/ss_cm_count.php ss_docsis_cmts_cm_count 'vm.domain.com' 'password' '1' '161' '500' RRD: /var/www/html/cacti/rra/villa_maria_manor_other_313.rrd
And it works for this device and shown in the graph https://imgur.com/a/0HWHCif

However if I run from SSH session I get zeroes for all results

Code: Select all

php /var/www/html/cacti/scripts/ss_cm_count.php ss_docsis_cmts_cm_count 'vm.domain.com' 'password' '1' '161' '500' RRD: /var/www/html/cacti/rra/villa_maria_manor_other_313.rrd
other:0 ranging:0 rangingAborted:0 rangingComplete:0 ipComplete:0 registrationComplete:0 accessDenied:0
On new devices it doesn't work through Script Server or command line. Doesn't make any sense to me.

netniV
Cacti Guru User
Posts: 3018
Joined: Sun Aug 27, 2017 12:05 am

Re: Custom script no longer runs on new Devices since upgrad

#7 Post by netniV » Sat Mar 02, 2019 4:25 pm

Sounds like the new device doesn't support it. Why don't you check with SNMPWALK ? Either that or your have the wrong configuration options for the SNMP of the device.

kevandju
Posts: 44
Joined: Tue Oct 10, 2006 3:30 pm

Re: Custom script no longer runs on new Devices since upgrad

#8 Post by kevandju » Sat Mar 02, 2019 5:44 pm

The new device is the same as the old device and I can use MIB Browser and pull all the values from the OID without issue.

The issue is the Script Server and php from command line I get 0's for all results with script on NEW devices

On OLD devices the script works fine and populates the data using the Script Server but it's all 0's if I run from command line with php. That is what I showed in my last post with running same command as in poller cache and getting 0's and I attached an image to show that Script Server is still somehow able to get data into my graphs.

netniV
Cacti Guru User
Posts: 3018
Joined: Sun Aug 27, 2017 12:05 am

Re: Custom script no longer runs on new Devices since upgrad

#9 Post by netniV » Sat Mar 02, 2019 7:48 pm

Then it sounds like either your custom script is wrong or you're querying the wrong OIDs or your device requires you define the access list of connecting SNMP devices. Hard to say without knowing your custom script and having access to diagnose what's going on. If all else fails, but debug statements into the script and see what it's actually trying to do, then verify manually it's right.

kevandju
Posts: 44
Joined: Tue Oct 10, 2006 3:30 pm

Re: Custom script no longer runs on new Devices since upgrad

#10 Post by kevandju » Sat Mar 02, 2019 10:22 pm

I copied and pasted the custom script into my first post. Is there a place to hire someone to debug this as everything I’ve documented is the extent of what I know to do to troubleshoot.

User avatar
camerabob
Cacti User
Posts: 296
Joined: Fri Feb 10, 2017 2:45 pm
Location: Long Island, New York, USA
Contact:

Re: Custom script no longer runs on new Devices since upgrad

#11 Post by camerabob » Tue Mar 05, 2019 9:32 am

By any chance, was the OS updated as well? This could be a difference on that layer too.
See the Cacti 1.x templates I use at: http://www.camerabob.com/cacti

Live: Cacti 1.2.3 @ CentOS 7-6.1810.2.el7 & PHP 5.4.16-46.el7
Flowview @ 2.1
Mactrack @ 4.2
Maint @ 1.2
Monitor @ 2.3.6
Thold @ 1.2.4

Test: Cacti 1.2.6-1.el7 @ CentOS 7-7.1908.0.el7 & PHP 5.4.16-46.el7
Maint @ 1.2
Monitor @ 2.3.6
Thold @ 1.2.4

Rno
Cacti User
Posts: 350
Joined: Wed Dec 07, 2011 9:19 am

Re: Custom script no longer runs on new Devices since upgrad

#12 Post by Rno » Tue Mar 05, 2019 10:23 am

any error on http log or php log ?

Can you add some debug (echo or print_r) on your script, it will help

Any issue with the user used to test the script ?
CentOS
Production
Cacti 0.8.8h
Spine 0.8.8h
PIA 3.1
Aggregate 0.75
Monitor 1.3
Settings 0.71
Weathermap 0.98
Thold 0.5
rrdclean 0.41

Own plugin: LinkDiscovery 0.45, Map 0.37

Test
Cacti 1.2.6
Spine 1.2.6
thold 1.0.6
monitor 2.3.5
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.6
Map 1.2.6

kevandju
Posts: 44
Joined: Tue Oct 10, 2006 3:30 pm

Re: Custom script no longer runs on new Devices since upgrad

#13 Post by kevandju » Tue Mar 05, 2019 10:27 am

Guys with help I found the fix/workaround

1. Goto the Data Input Method, edit it, edit one of the rows, hit save, hit save on the input method
2. Goto the Data Source Template, edit it, save it
3. Goto the Graph Template, edit it, save it, return from it, select it in the list, sync it (actions at the bottom)
4. Goto the Device Template, edit it, save it, return from it, select it in the list, sync it (actions at the bottom)

After that it started working again. Thanks for all the help!

netniV
Cacti Guru User
Posts: 3018
Joined: Sun Aug 27, 2017 12:05 am

Re: Custom script no longer runs on new Devices since upgrad

#14 Post by netniV » Tue Mar 05, 2019 10:42 am

When this template is imported, there is no field order. Any devices created with the template don't have all the various fields they should have.

By performing the above, the template is refreshed and pushed back to the datasources/devices/graphs which makes the missing fields properly link.

Not sure yet why that is occurring as when importing the field order should just work.

Post Reply