1<?php 2/** 3 * Display SNMP values 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 * @author Michael Luggen <michael.luggen@unifr.ch> 8 */ 9 10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12require_once(DOKU_PLUGIN.'syntax.php'); 13 14class syntax_plugin_snmplive extends DokuWiki_Syntax_Plugin { 15 /** 16 * return some info 17 */ 18 function getInfo(){ 19 return array( 20 'author' => 'Michael Luggen', 21 'email' => 'michael.luggen@unifr.ch', 22 'date' => '2007-03-08', 23 'name' => 'SNMPlive Plugin', 24 'desc' => 'Updates various SNMP data live.', 25 'url' => 'http://wiki.splitbrain.org/plugin:gallery', 26 ); 27 } 28 29 /** 30 * What kind of syntax are we? 31 */ 32 function getType(){ 33 return 'substition'; 34 } 35 36 /** 37 * What about paragraphs? 38 */ 39 function getPType(){ 40 return 'normal'; 41 } 42 43 /** 44 * Where to sort in? 45 */ 46 function getSort(){ 47 return 334; 48 } 49 50 /** 51 * Connect pattern to lexer 52 */ 53 function connectTo($mode) { 54 $this->Lexer->addSpecialPattern('<snmplive.*?>',$mode,'plugin_snmplive'); 55 } 56 57 58 /** 59 * Handle the match 60 */ 61 function handle($match, $state, $pos, &$handler){ 62 $match = substr($match,9,-1); //strip markup from start and end 63 64 //get values 65 $param = array(); 66 $values = array(); 67 preg_match_all('/(\w*)="(.*?)"/us',$match,$param,PREG_SET_ORDER); 68 69 foreach($param as $value) { 70 list($m,$k,$v) = $value; 71 $values[$k] = $v; 72 } 73 74 return $values; 75 } 76 77 /** 78 * Create output 79 */ 80 function render($mode, &$renderer, $data) { 81 if($mode == 'xhtml'){ 82 $renderer->doc .= "<span id=\"".$data['ip'].$data['oid']."\">"; 83 $renderer->doc .= $this->_getSNMPdata($data['ip'], $data['oid']); 84 $renderer->doc .= "</span>"; 85 $renderer->doc .= $this->_script($data['ip'],$data['oid']); 86 return true; 87 } 88 return false; 89 } 90 91 function _script($ip,$oid){ 92 $str = '<script type="text/javascript" language="javascript">'; 93 $str .= "addEvent(window,'load',plugin_snmplive('".$ip."','".$oid."'));"; 94 $str .= '</script>'; 95 return $str; 96 } 97 98 /** 99 * Returns the value of the "snmp variable" 100 * 101 * @author Michael Luggen <michael.luggen@unifr.ch> 102 */ 103 function _getSNMPdata($ip,$oid){ 104 return preg_replace('/(\w+)\: "?([^".]+)"?/','${2}',snmpget($ip, 'public', $oid)); 105 } 106} 107 108//Setup VIM: ex: et ts=4 enc=utf-8 : 109