Ad blocker detected: Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker on our website.
If you are having problems with the PHP Script Server, please follow the instructions below:
1) Start PHP Script Server
Use the following command to start the script server: "php <path_cacti>/script_server.php"
You wll receive a message from PHP indicating "PHP Script Server Started Properly". If you get any warning messages, then you have to fix them right away.
2) Obtain a Script Command from the Poller Cache
a) To do this Goto System Utilities->View Poller Cache
b) Search for "Action: 2"
c) Copy the portion of the script starting with the full path and working
to the end of line. For example:
c:\wwwroot\cacti086\scripts\ss_host_cpu.php ss_host_cpu localhost public 2 161 500 get usage 0
3) Execute the Script Server Command
Paste the command from 2c into your Script Server window and press enter.
You should receive an output statement. If not, please correct any warnings or script errors before proceeding.
4) To End the Script Server session
Type "quit" in the Script Server window and press enter.
Important Note:
For older versions of PHP < 4.3.3, you should be able to execute the command cut from setp 2c directly to a command line prefixed by "php" and run that script stand alone.
TheWitness
True understanding begins only when we realize how little we truly understand...
Hello,
I would like to know what are advantages of the method "script server" compared to "snmp query" ?
When I compare "net-snmp_disk.xml" description and "ss_host_disk.php" design, and according to the poller cache information, I think the "net-snmp_disk" should be faster to process than script server 'host_disk" because cmd.php or cactid can collect value from a single OID directly without invoking a script. Am I right ?
When designing a new data collector, is it better to use "snmp query" (when possible of course ) or "script server" ?
SNMP Queries will always be orders of magnitude faster especially using Cactid due to the fact that we are using RAW protocol with SNMP vs. a script that essentially does the same. The Script Server speeds up scripts when compared to a native shell or perl call however.
TheWitness
True understanding begins only when we realize how little we truly understand...
I've got a problem with the migration from an existing PHP script to Script Server method, I just follow the doc steps ("Migration of Existing PHP Scripts to Script Server") and my graphs are stopped (nothing in the poller cache).
So, I have to manually create new graphs with the script server method, it goes very well (results tested with the CLI script_server.php are right compared to stand alone script).
The opposite transition works fine (from stand alone script to script server).
Did I miss another step during the migration ?
I would have to see specificatlly what you did. It does work though. Prior to migration, you should always test your script as both script and non-script. The nice thing about the script itself, it should work both ways. Once you have that done, and graphing, you can change your data input method to be script server. Last step is to re-populate your poller cache.
TheWitness
True understanding begins only when we realize how little we truly understand...
+ Running data query [10].
+ Found type = '4 '[script query].
+ Found data query XML file at '/var/www/public/cacti/resource/script_queries/class_qos.xml'
+ XML file parsed ok.
+ Executing script for list of indexes '/usr/bin/php -q /var/www/public/cacti/scripts/qos_plug.php class *.*.*.* comm 2 index'
+ Executing script query '/usr/bin/php -q /var/www/public/cacti/scripts/qos_plug.php class *.*.*.* comm 2 query index'
....
Script: /usr/bin/php -q /var/www/public/cacti/scripts/qos_plug.php class *.*.*.* comm 2 get cbQosCMDropByte 2.class-default
RRD: /var/www/public/cacti/rra/routeur_cisco_1_cmpostpolicybyte_76.rrd
And this is the verbose query for ss_qos_plug.php :
+ Running data query [10].
+ Found type = '6 '[script query].
+ Found data query XML file at '/var/www/public/cacti/resource/script_server/class_qos.xml'
+ XML file parsed ok.
+ Executing script for list of indexes '/usr/bin/php -q /var/www/public/cacti/scripts/ss_qos_plug.php class *.*.*.* comm 2 index'
+ Executing script query '/usr/bin/php -q /var/www/public/cacti/scripts/ss_qos_plug.php class *.*.*.* comm 2 query index'
....
Script Server: /var/www/public/cacti/scripts/ss_qos_plug.php ss_qos_plug class *.*.*.* comm 2 get cbQosCMDropByte 2.class-default
RRD: /var/www/public/cacti/rra/routeur_cisco_1_cmpostpolicybyte_76.rrd
112 items, 16 rows in the two cases. There is no difference between the results.
When the ss_qos_plug.php is running and when I change to qos_plug.php, there is no problem, Cacti continue to graph, the poller cache is correctly rebuilt.
But in the other direction, when I rebuild poller cache, nothing happens (the poller requests disappear), so I have to delete Data Sources and create new graphs with old rrd files (to keep history).
The "plller" quote you showed is actually the "poller cache". So from that, it would, in fact, appear to be being added. However, it is likely not running for some reason. Have you tested outside of the poller yet:
So, everything "should" be working. Do you see any issues when you run "php -q poller.php" from a command line? If you get that information in your log, then the only thing to break the graph would be an rrdupdate issue that you would be able to see by running "php -q poller.php".
TheWitness
True understanding begins only when we realize how little we truly understand...
I have a system on Cacti 0.8.8a in VM environment. I have created a clone of the same and upgraded Cacti from 0.8.8a to 0.8.8d on it. After upgrade every thing is working fine except few script server queries. I am getting NAN value on all the graphs that are getting data from these script server queries. On my Cacti 0.8.8a server when I tested poller cache query manually I got correct result against a get query (see below).
[root@seth cacti]$php script_server.php
PHP Script Server has Started - Parent is cmd
/tools/cacti-0.8.8a/scripts/ss_globalStats.php ss_globalStats TEST-01 2413 get ActiveEpsBearer global
608896
quit
PHP Script Server Shutdown request received, exiting
But when I tried same test on new Cacti version on clone system.
PHP Script Server has Started - Parent is cmd
/tools/cacti-0.8.8d/scripts/ss_globalStats.php ss_globalStats TEST-01 2413 get ActiveEpsBearer global
quit
PHP Script Server Shutdown request received, exiting
608966You have mail in /var/spool/mail/root
So here result of get is coming after "quit", don't know why. This has resulted NAN value on all the graphs.
Is there any problem with my below code?
Cacti 0.8.8d
Spine 0.8.8a [0.8.8d did not worked after compilation so I have used old spine 0.8.8a as per suggestion from a Cacti forum]
Plugin Architecture Version: 3.1
Cacti Multipoller server 0.8.8d
It has been resolved now after changing the print command with return. It was working on Cacti 0.8.8a but now need to use return for "get" function in the server script on Cacti 0.8.8d or Cacti 0.8.8e. Now this issue is resolved.
I wrote perl and php scripts to connect by ssh to our new AirFiber AF5X HD devices. I haven't yet found a way to do this on the Airfiber with SNMP though I was able to get cpu load averages. Probably I am not going about it the easiest way but wanted to use the php script server to preload the code and make it more efficient. I did research and was somewhat confused by the Data Query XML specifications vs just running as a script server with appropriate modification to the regular script. So I am posting here for other cacti newbies step by step and looking for tips to improve and/or correct mistakes. I did use the cacti site and some php ssh2 references so hat's off to my sources.
<?php
$no_http_headers = true;
// to test script in script server
// php /usr/share/cacti/script_server.php
// /usr/share/cacti/scripts/ss_afthroughput.php ss_afthroughput IP_ADDRESS admin ssh_passwd
function ss_afthroughput($host='IP_ADDRESS',$user='admin',$pass='ssh_passwd') {
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
$cmd = '/usr/www/status.cgi | sed \'1,2d\' | sed s/\,\"time_sec.*// | sed s/.*rx_throughput/RX/ | sed s/\,\"tx_bytes.*tx_throughput/\ TX/ | sed s/\"\:/\:\/g';
$connection = ssh2_connect($host, 22, $methods, $callbacks);
if (!$connection) die("Connection failed:");
ssh2_auth_password($connection, $user, $pass) or die("Unable to authenticate");
$stream = ssh2_exec($connection, $cmd);
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
return stream_get_contents($stream_out);
}
/* Notify the user if the server terminates the connection */
function ssh_disconnect($reason, $message, $language) {
printf("Server disconnected with reason code [%d] and message: %s\n", $reason, $message);
}
?>
I copied this to /usr/share/cacti/scripts. I initially tried making an XML and decided this probably wasn't necessary ... and it works.
So hopefully the code is cached in the script server though not a Data Query?
Go to Console / Data Collection / Data Input Methods / and add a new data source
Name AirFiber - SS_Throughput
Input Type Script Server
Input String<path_cacti>/scripts/ss_afthroughput.php ss_afthroughput <hostname> <username> <password>
Input Fields
hostname Hostname 1
username Username 2
password Password 3
Output Fields
RX Recieved Throughput Selected (update rrd file toggle on)
TX Transmitted Throughput Selected (update rrd file toggle on)
I am not sure what the use is of passing the function name to the script when I don't need it to run the script though it might be useful if I wanted to select than one function.
I also wasn't able to pass the $_SERVER['argv'] as an array so passed individual values, I'm a little weak in php.
Go to Console / Template / Data Source / add a new data source
AirFiber - SS_Throughput *Edit Data Input Method.
Name |host_description| - AirFiber SS_Throughput
Data Source Name AirFiber - SS_Throughput
Name |host_description| - SS_Throughput
Data Input Method Airfiber SS_Throughput
Data Source Profile
Data Source Active
1: RX
2: TX
Data Source Item [RX]
Internal Data Source Name
Minimum Value ("U" for No Minimum) 0
Maximum Value ("U" for No Maximum) U
Data Source Type
Output Field
Custom Data [data input: AirFiber - SS_Throughput]
Hostname
Password ssh_password
Username admin_username in this case airfiber uses admin
You need to add input and output fields, input will be hostname username and password .. check the toggle to allow changes to username and password after creation
For output add first RX then TX and select the correct Output Field RX - Recieved Output for RX and TX - Transmitted Throughput for TX
and Save
Go to Templates / Graph / I would just copy one of the other graphs for Interface throughput I think I used the 95th percentile graph. You manually copy the template or just select the graph and make a copy and make the copie's name AirFiber - SS_Througkput.
Delete all the data sources from graph item inputs, these will be recreated.
Go to each indivdual graph item and change the Data Input Filter to Airfiber SS_Throughput and Data Source to the RX for old RX entries and TX for old TX entries aka in and out.
Save the graph when done.
Go to Management / Devices and select the device to edit
Go to add a graph template and add Airfiber SS_Throughput - modify username and password though you can set defaults in the data source template
And, it should say graphing, after the poller runs once it should show up under graphs