Cacti (home)ForumsDocumentation

Differences

This shows you the differences between two versions of the page.

manual:088:3a_advanced_topics.2_php_script_server [2010/10/29 13:14]
TheWitness Someone changed "return" to "Print". Changing back again.
manual:088:3a_advanced_topics.2_php_script_server [2019/10/29 15:16] (current)
Line 6: Line 6:
  
 Since PHP scripts are so powerful, this new feature in Cacti, makes it an excellent choice for collecting non-SNMP and SNMP based data. Since PHP scripts are so powerful, this new feature in Cacti, makes it an excellent choice for collecting non-SNMP and SNMP based data.
 +
  
 ==== Using the PHP Script Server ==== ==== Using the PHP Script Server ====
 +
 +The technique that is applied here uses the PHP //include// method. Assume, that your script is called //myscript//. For convenience, we prepend PHP script server modules with a prefix of //ss_//, denoting the use of //s//cript //s//erver. This makes the following name: //ss_myscript.php//. Now, write your code as part of a function, that will be included by the script server. Again, for convenience, we use the module's name as the name (of the first) function: //ss_myfunction//. Now we have a PHP module called //ss_myscript.php// which includes a function called //ss_myfunction// that has all your code.
 +
 +As an extension, please note that a single module //ss_myscript.php// may hold several distinct functions, e.g. //ss_myfunction1// and //ss_myfunction2// and so on.
  
 Cacti 0.8.7 contains two sample script server routines. They are for the collection of HostMib CPU and Disk Partition information. These two examples are based off the traditional POPEN version of the HostMib functions found in earlier versions of Cacti. Cacti 0.8.7 contains two sample script server routines. They are for the collection of HostMib CPU and Disk Partition information. These two examples are based off the traditional POPEN version of the HostMib functions found in earlier versions of Cacti.
Line 14: Line 19:
  
 For upgrades, you must make several changes to start using the PHP Script Server for the HostMib CPU and HostMib Partitions Data Queries. To migrate you must follow the step For upgrades, you must make several changes to start using the PHP Script Server for the HostMib CPU and HostMib Partitions Data Queries. To migrate you must follow the step
 +
 +
 ==== Upgrade Steps for the Example HostMib Data Queries ==== ==== Upgrade Steps for the Example HostMib Data Queries ====
  
Line 29: Line 36:
  
 Following those steps should complete your migration to the new PHP Script Server for the two example HostMIB Data Queries. Following those steps should complete your migration to the new PHP Script Server for the two example HostMIB Data Queries.
 +
 +
 ==== Migration of Existing PHP Scripts to Script Server ==== ==== Migration of Existing PHP Scripts to Script Server ====
  
Line 56: Line 65:
 ?></PHP>Would become:<PHP> ?></PHP>Would become:<PHP>
 function ss_myfunction() { function ss_myfunction() {
-$a = 100; +   $a = 100; 
-$b = $a / 10; +   $b = $a / 10; 
-return $b;+   return $b;
 }</PHP> }</PHP>
   - If you have any additional functions declared within your script file, you must prefix them to make then unique amongst all functions. Our recommendation would be to prefix all functions with the name of the main function. For example if you have a function called "meme" you would rename it to "ss_myfunction_meme". This guarantee's correct Script Server functionality.   - If you have any additional functions declared within your script file, you must prefix them to make then unique amongst all functions. Our recommendation would be to prefix all functions with the name of the main function. For example if you have a function called "meme" you would rename it to "ss_myfunction_meme". This guarantee's correct Script Server functionality.
Line 67: Line 76:
 If you are using a "//Script Query//" type function, then you must also change your XML file. Please reference the XML files in the <path_cacti>/resource/script_server directory for the specifics related to your required modifications. However, you may also follow the instructions below: If you are using a "//Script Query//" type function, then you must also change your XML file. Please reference the XML files in the <path_cacti>/resource/script_server directory for the specifics related to your required modifications. However, you may also follow the instructions below:
  
-  - Modify the <script_path> tag. Change it from:<code><script_path>|path_php_binary| -q |path_cacti|/scripts/myfucntion.php</script_path></code>to simply the following:<code> +  - Modify the <script_path> tag. Change it from:<code><script_path>|path_php_binary| -q |path_cacti|/scripts/myscript.php</script_path></code>to simply the following:<code> 
-<script_path>|path_cacti|/scripts/ss_myfunction.php</script_path></code>+<script_path>|path_cacti|/scripts/ss_myscript.php</script_path></code>
   - Add the following two XML tags below the <script_path> tag. Replace **ss_myfunction** with your function name:<code>   - Add the following two XML tags below the <script_path> tag. Replace **ss_myfunction** with your function name:<code>
 <script_function>ss_myfunction</script_function> <script_function>ss_myfunction</script_function>





Personal Tools