plugin:snmplive
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:snmplive [2008-09-18 16:12] – 70.88.147.57 | plugin:snmplive [2017-11-25 21:16] (current) – Aleksandr | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== snmplive Plugin ====== | ||
+ | ---- plugin ---- | ||
+ | description: | ||
+ | author | ||
+ | email : michael.luggen@unifr.ch | ||
+ | type : syntax | ||
+ | lastupdate : 2009-01-13 | ||
+ | compatible : | ||
+ | depends | ||
+ | conflicts | ||
+ | similar | ||
+ | tags : ajax, management, ip | ||
+ | downloadurl: | ||
+ | ---- | ||
+ | |||
+ | //Based on the [[plugin: | ||
+ | |||
+ | It gets the actual [[wp> | ||
+ | |||
+ | ===== Usage ===== | ||
+ | |||
+ | You need the IP of the device and the exact oid... NEW: You can now also set the community. | ||
+ | |||
+ | < | ||
+ | |||
+ | ==== Collection of interesting OID's ==== | ||
+ | |||
+ | * http:// | ||
+ | * .1.3.6.1.2.1.43.16.5.1.2.1.1 as example shows whats on the Display | ||
+ | |||
+ | ===== History ===== | ||
+ | |||
+ | * 2009-01-13: enhancement of community-flag by Alexandre Morel | ||
+ | * 2007-03-08: first Version | ||
+ | |||
+ | ===== Code ===== | ||
+ | |||
+ | Create a directory called '' | ||
+ | |||
+ | ==== syntax.php ==== | ||
+ | |||
+ | Create this file in '' | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | /** | ||
+ | * Display SNMP values | ||
+ | | ||
+ | * @license | ||
+ | * @author | ||
+ | * @author | ||
+ | */ | ||
+ | |||
+ | if(!defined(' | ||
+ | if(!defined(' | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | class syntax_plugin_snmplive extends DokuWiki_Syntax_Plugin { | ||
+ | /** | ||
+ | * return some info | ||
+ | */ | ||
+ | function getInfo(){ | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * What kind of syntax are we? | ||
+ | */ | ||
+ | function getType(){ | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * What about paragraphs? | ||
+ | */ | ||
+ | function getPType(){ | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Where to sort in? | ||
+ | */ | ||
+ | function getSort(){ | ||
+ | return 334; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Connect pattern to lexer | ||
+ | */ | ||
+ | function connectTo($mode) { | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | |||
+ | /** | ||
+ | * Handle the match | ||
+ | */ | ||
+ | function handle($match, | ||
+ | $match = substr($match, | ||
+ | |||
+ | //get values | ||
+ | $param = array(); | ||
+ | $values = array(); | ||
+ | preg_match_all('/ | ||
+ | |||
+ | foreach($param as $value) { | ||
+ | list($m, | ||
+ | $values[$k] = $v; | ||
+ | } | ||
+ | |||
+ | return $values; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Create output | ||
+ | */ | ||
+ | function render($mode, | ||
+ | if($mode == ' | ||
+ | $renderer-> | ||
+ | $renderer-> | ||
+ | $renderer-> | ||
+ | $renderer-> | ||
+ | return true; | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | function _script($ip, | ||
+ | $str = '< | ||
+ | $str .= " | ||
+ | $str .= '</ | ||
+ | return $str; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Returns the value of the "snmp variable" | ||
+ | * | ||
+ | * @author Michael Luggen < | ||
+ | */ | ||
+ | function _getSNMPdata($ip, | ||
+ | return preg_replace('/ | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | ==== ajax.php ==== | ||
+ | |||
+ | This is the backend to handle the AJAX requests. Put it into '' | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | /** | ||
+ | * AJAX Backend Function for plugin_snmplive | ||
+ | * | ||
+ | * @author Andreas Gohr < | ||
+ | * @author Michael Luggen < | ||
+ | */ | ||
+ | |||
+ | //fix for Opera XMLHttpRequests | ||
+ | if(!count($_POST) && $HTTP_RAW_POST_DATA){ | ||
+ | parse_str($HTTP_RAW_POST_DATA, | ||
+ | } | ||
+ | |||
+ | if(!defined(' | ||
+ | if(!defined(' | ||
+ | require_once(DOKU_INC.' | ||
+ | //close sesseion | ||
+ | session_write_close(); | ||
+ | |||
+ | require_once(DOKU_INC.' | ||
+ | require_once(DOKU_INC.' | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | header(' | ||
+ | $SNMPip = cleanID($_POST[' | ||
+ | $SNMPoid = cleanID($_POST[' | ||
+ | $SNMPcommunity = cleanID($_POST[' | ||
+ | print syntax_plugin_snmplive:: | ||
+ | ?> | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== script.js ==== | ||
+ | |||
+ | The needed JavaScript goes into '' | ||
+ | |||
+ | <code javascript> | ||
+ | /** | ||
+ | * Script for plugin_snmplive | ||
+ | * | ||
+ | * Fetches the new snmpvalues | ||
+ | * | ||
+ | * @author Andreas Gohr < | ||
+ | * @author Michael Luggen < | ||
+ | */ | ||
+ | |||
+ | function plugin_snmplive(ip, | ||
+ | var snmpId = ip + oid + community; | ||
+ | if(!document.getElementById){ | ||
+ | return; | ||
+ | } | ||
+ | var obj = document.getElementById(snmpId); | ||
+ | if(obj === null){ | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // We use SACK to do the AJAX requests | ||
+ | var ajax = new sack(DOKU_BASE+' | ||
+ | ajax_qsearch.sack.AjaxFailedAlert = ''; | ||
+ | ajax_qsearch.sack.encodeURIString = false; | ||
+ | |||
+ | // define callback | ||
+ | ajax.onCompletion = function(){ | ||
+ | var data = this.response; | ||
+ | if(data === '' | ||
+ | var out = document.getElementById(snmpId); | ||
+ | |||
+ | out.style.visibility = ' | ||
+ | out.innerHTML = data; | ||
+ | out.style.visibility = ' | ||
+ | |||
+ | // restart timer | ||
+ | window.setTimeout(" | ||
+ | }; | ||
+ | |||
+ | ajax.runAJAX(' | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Install from tarball ===== | ||
+ | |||
+ | There' | ||
+ | <code sh> | ||
+ | $ make install prefix=/ | ||
+ | </ | ||
+ | |||
+ | ===== Known Issues ===== | ||
+ | |||
+ | * it can not resolve hostnames (yet) | ||
+ | * little problems with the ajax frame work (throws 2 errors at the beginning) | ||
+ | * data is not cached (should cache like rss feeds are cached) | ||
+ | |||
+ | ===== Discussion ===== | ||
+ | I have just installed this plugin using the plugin manager.\\ | ||
+ | If I insert any < | ||
+ | |||
+ | I am using the monobook template (in case that's significant).\\ | ||
+ | // | ||
+ | |||
+ | weird, hostnames are resolved for me, using php 5.2.3. however i noticed it first lowercases the oid names and secondly issues some warning: | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | PHP Warning: | ||
+ | </ | ||
+ | |||
+ | however it outputs result ok to the page. | ||
+ | |||
+ | --- // | ||
+ | |||
+ | A prerequisite for this plugin is the snmp package for php5. | ||
+ | On a Debian system you could do | ||
+ | |||
+ | apt-get install php5-snmp | ||
+ | |||
+ | --- // | ||
+ | | ||
+ | Can anyone guide me how to sum several snmplive outputs in dokuwiki? | ||
+ | |||
+ | --- // | ||
+ | |||
+ | I finally figured it out. You will need [[plugin: | ||
+ | | ||
+ | |**PDU1**|< | ||
+ | |**PDU2**|< | ||
+ | |**PDU3**|< | ||
+ | |**PDU4**|< | ||
+ | |**Total input feed:**| ~~=r0c1+r1c1+r2c1+r3c1~~< | ||
+ | |**Annual cost estimate based on the total power consumption of the system at this load (11¢/ | ||
+ | | ||
+ | --- // | ||
+ | |||
+ | --- // | ||
+ | |||
+ | I am struggling to get any output. If I run the command for SNMPGET from command line I get the expected result\\ | ||
+ | But running in Dokuwiki I get\\ | ||
+ | Warning: snmpget(): No response from xxxxx in / | ||
+ | |||
+ | --- // |