Custom script no longer runs on new Devices since upgrade

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

Moderators: Developers, Moderators

Post Reply
kevandju
Posts: 45
Joined: Tue Oct 10, 2006 3:30 pm

Custom script no longer runs on new Devices since upgrade

Post by kevandju »

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: 3441
Joined: Sun Aug 27, 2017 12:05 am

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

Post by netniV »

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.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
kevandju
Posts: 45
Joined: Tue Oct 10, 2006 3:30 pm

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

Post by kevandju »

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: 45
Joined: Tue Oct 10, 2006 3:30 pm

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

Post by kevandju »

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?
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

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

Post by netniV »

Did you run the command as shown in the poller cache?
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
kevandju
Posts: 45
Joined: Tue Oct 10, 2006 3:30 pm

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

Post by kevandju »

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: 3441
Joined: Sun Aug 27, 2017 12:05 am

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

Post by netniV »

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.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
kevandju
Posts: 45
Joined: Tue Oct 10, 2006 3:30 pm

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

Post by kevandju »

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: 3441
Joined: Sun Aug 27, 2017 12:05 am

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

Post by netniV »

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.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
kevandju
Posts: 45
Joined: Tue Oct 10, 2006 3:30 pm

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

Post by kevandju »

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: 386
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

Post by camerabob »

By any chance, was the OS updated as well? This could be a difference on that layer too.
Prod: Cacti 1.2.15 @ CentOS Linux release 7.9.2009 (Core) & PHP 5.4.16-48.el7
Maint @ 1.2
Monitor @ 2.3.6
Thold @ 1.2.4

Temp: Cacti 1.2.3 @ CentOS Linux release 7.9.2009 (Core) & PHP 5.4.16-48.el7
Flowview @ 2.1
Mactrack @ 4.2
Maint @ 1.2
Monitor @ 2.3.6
Router Configs @ 1.3.4
Syslog Monitoring @ 2.1
Thold @ 1.2.4
Rno
Cacti Pro User
Posts: 704
Joined: Wed Dec 07, 2011 9:19 am

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

Post by Rno »

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 ?
Test
Almalinux
php 8.2.14
mariadb 10.6.16
Cacti 1.2.27
Spine 1.2.27
RRD 1.7.2
thold 1.8
monitor 2.5
syslog 3.2
flowview: 3.3
weathermap 1.0 Beta
kevandju
Posts: 45
Joined: Tue Oct 10, 2006 3:30 pm

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

Post by kevandju »

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: 3441
Joined: Sun Aug 27, 2017 12:05 am

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

Post by netniV »

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.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests