Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Mon Mar 25, 2019 12:50 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Custom script no longer runs on new Devices since upgrade
PostPosted: Fri Mar 01, 2019 5:56 pm 
Offline

Joined: Tue Oct 10, 2006 3:30 pm
Posts: 44
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:
<?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;
}


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Fri Mar 01, 2019 6:17 pm 
Offline
Cacti Guru User

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

_________________
Official Cacti Developer

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

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Fri Mar 01, 2019 6:36 pm 
Offline

Joined: Tue Oct 10, 2006 3:30 pm
Posts: 44
When I run from command line on device that is graphing properly I still don't get results

Code:
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.

Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Fri Mar 01, 2019 7:01 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Sat Mar 02, 2019 4:35 am 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2296
Did you run the command as shown in the poller cache?

_________________
Official Cacti Developer

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

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Sat Mar 02, 2019 11:18 am 
Offline

Joined: Tue Oct 10, 2006 3:30 pm
Posts: 44
This is what poller cache says

Code:
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:
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.


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Sat Mar 02, 2019 4:25 pm 
Offline
Cacti Guru User

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

_________________
Official Cacti Developer

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

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Sat Mar 02, 2019 5:44 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Sat Mar 02, 2019 7:48 pm 
Offline
Cacti Guru User

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

_________________
Official Cacti Developer

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

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Sat Mar 02, 2019 10:22 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Tue Mar 05, 2019 9:32 am 
Offline
Cacti User
User avatar

Joined: Fri Feb 10, 2017 2:45 pm
Posts: 224
Location: Long Island, New York, USA
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.2 @ CentOS 7-6.1810.2.el7
Test: Cacti 1.2.2 @ CentOS 7-6.1810.2.el7


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Tue Mar 05, 2019 10:23 am 
Offline
Cacti User

Joined: Wed Dec 07, 2011 9:19 am
Posts: 321
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.3, Map 0.4

Test
Cacti 1.2.1
Spine 1.2.1
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.4
Map 1.2.5


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Tue Mar 05, 2019 10:27 am 
Offline

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


Top
 Profile  
 
 Post subject: Re: Custom script no longer runs on new Devices since upgrad
PostPosted: Tue Mar 05, 2019 10:42 am 
Offline
Cacti Guru User

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

_________________
Official Cacti Developer

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

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


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

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 9 guests


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