jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [docs/] [pages/] [advanced.html] - Blame information for rev 21

 

Line No. Rev Author Line
11simandl<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 
4<html lang="en" xml:lang="en">
5<head>
6 <link rel="stylesheet" type="text/css" media="screen" href="weathermap.css" />
7 <meta name="generator" content=
8 "HTML Tidy for Mac OS X (vers 12 April 2006), see www.w3.org" />
9 
10 <title>PHP Weathermap
11v0.91
12 - Advanced Topics</title>
13<style type="text/css" media="print">
14/*<![CDATA[*/
15body { font-size: 12pt; }
16a { color: black; text-decoration: underline; font-weight: normal;}
17/*]]>*/
18</style>
19 
20</head>
21 
22<body>
23 <div id="frame">
24 
25 
26<div class="navcontainer">
27 <ul id="navlist">
28 <li><a href="main.html">Main Page</a></li>
29 <li><a href="main.html#installation">Installation</a></li>
30 <li><a href="main.html#basics">Basics</a></li>
31 <li><a href="faq.html">FAQ and Tips</a></li>
32 <li><a href="main.html#example">Sample Map</a></li>
33 <li><a href="cli-reference.html">CLI Reference</a></li>
34 <li><a href="config-reference.html">Config Reference</a></li>
35 <li><a href="advanced.html">Advanced Topics</a></li>
36 <li><a href="editor.html">Editor</a></li>
37 <li><a href="cacti-plugin.html">Cacti Plugin</a></li>
38 <li><a href="http://www.network-weathermap.com/">Site</a></li>
39 </ul>
40</div>
41 
42<div id="header">
43 <h1>PHP Weathermap
44v0.91
45</h1>
46 <h4>Copyright &copy; 2005-2007 Howard Jones, <tt><a
47href="mailto:howie@thingy.com">howie@thingy.com</a></tt>. (<a
48href="http://www.network-weathermap.com/">Website</a>)</h4>
49</div>
50 
51 
52 <h2><a name="editor" id="editor">Advanced Topics</h2>
53 <p>This page contains information for the more advanced corners of Weathermap usage. I assume that you are more familiar with the basics of map design here - there is less explanation of the simple stuff.</p>
54 
55 <h2><a name="tokens">Special String Processing Tokens</a></h2>
56 
57<p>Most places where you can specify a string in Weathermap config files, you can now include data from within the Weathermap data model. Useful examples of this would be:
58<ul>
59<li>You can have the value of a data source printed in the map.</li>
60<li>You can have <a href="config-reference.html#NODE_ICON">ICON</a> filenames which change with the value of a datasource.</li>
61<li>You can make more effective use of the DEFAULTs, by including parameterised LABELs, ICONs and OVERLIBCAPTIONs.</li>
62</ul>
63Finally, plugins can add internal 'notes' to objects in the map, which you can then use in the same way as the normal Weathermap data. For example, you could have a plugin that looks at the load-average on a server, categorises it as light, medium or heavy and saves that to a note, which can then be used to select an appropriate icon.
64</p>
65<p>The format for the tokens is simple:
66<div class="definition">{node:<em>nodename</em>:<em>variablename</em>}</div>
67<div class="definition">{link:<em>linkname</em>:<em>variablename</em>}</div>
68<div class="definition">{map:<em>variablename</em>}</div>
69 
70Where nodename and linkname are the names of nodes or links defined in the map. There is a special link/node name, 'this', which always signifies the node or link that the string belongs to. For example:
71<div class="example"><pre>
72<a href="config-reference.html#NODE_NODE">NODE</a> test
73 <a href="config-reference.html#NODE_LABEL">LABEL</a> {node:this:name}
74 </pre>
75</div>
76will set the label for the node to be 'test', since that is the node's name. Using 'this' in the DEFAULT node can save you some typing:
77<div class="example"><pre>
78<a href="config-reference.html#NODE_NODE">NODE</a> DEFAULT
79 <a href="config-reference.html#NODE_LABEL">LABEL</a> {node:this:name}
80 <a href="config-reference.html#LINK_OVERLIBCAPTION">OVERLIBCAPTION</a> History for {node:this:name}
81 
82<a href="config-reference.html#NODE_NODE">NODE</a> test1
83 <a href="config-reference.html#NODE_POSITION">POSITION</a> 100 100
84 
85<a href="config-reference.html#NODE_NODE">NODE</a> test2
86 <a href="config-reference.html#NODE_POSITION">POSITION</a> 150 100
87 </pre>
88</div>
89Each node will take it's name as the label, and a useful caption for it's Overlib pop-up graph.
90</p>
91<p>For nodes specifically, there is one other special 'nodename' - 'parent'. If a node is positioned relative to another one, then this refers to that other node. The idea is to allow a node to be used as an additional data label for another one. </p>
92<p>
93Here is the list of valid <em>variablename</em>s and their meaning.
94<table class="biglist">
95<thead><tr><th>Variable Name</th><th>Meaning</th></tr></thead>
96<tbody>
97<tr>
98 <th>bandwidth_in</th>
99 <td>The raw 'bandwidth' figure for the input side of the item. This isn't always an actual bandwidth figure, especially for NODEs. For bandwidth, you probably want to use the formatting modifiers listed below.</td>
100</tr>
101<tr>
102 <th>bandwidth_out</th>
103 <td>The raw 'bandwidth' figure for the output side of the item. As above, but for output.</td>
104</tr>
105<tr>
106 <th>max_bandwidth_in</th>
107 <td>The maximum input bandwidth, as defined by <a href="config-reference.html#NODE_MAXVALUE">MAXVALUE</a> or BANDWIDTH.</td>
108</tr>
109<tr>
110 <th>max_bandwidth_out</th>
111 <td>The maximum output bandwidth, as defined by <a href="config-reference.html#NODE_MAXVALUE">MAXVALUE</a> or BANDWIDTH.</td>
112</tr>
113<tr>
114 <th>inpercent</th>
115 <td>The percentage usage for the input side of the item, calculated using the previous two figures.</td>
116 
117</tr>
118<tr>
119 <th>outpercent</th>
120 <td>The percentage usage for the output side of the item, calculated using the previous two figures.</td>
121</tr>
122<tr>
123 <th>name</th>
124 <td>The name of the <a href="config-reference.html#NODE_NODE">NODE</a> or LINK.</td>
125</tr>
126 
127</tbody>
128</table>
129</p>
130<p>In addition to the variables defined by Weathermap itself, there are two additional sources for variables, that greatly extend the usefulness of these string tokens: You, and Data Source Plugins.</p>
131<p>
132Firstly, you can define addition variables for any <a href="config-reference.html#NODE_NODE">NODE,</a> <a href="config-reference.html#LINK_LINK">LINK</a> or for the map in general, using the <a href="config-reference.html#GLOBAL_SET">SET</a> command. This serves two purposes. One is to allow you to give parameters to some datasource plugins (like a database password for some external database), but the other is just so you can use those values elsewhere in the map.
133Say you have a data-collection system where each router has an ID, but the URL is otherwise the same from one <a href="config-reference.html#NODE_NODE">NODE</a> to the next. You can define a new variable with the router ID, and then use a string token to insert that ID into the <a href="config-reference.html#LINK_INFOURL">INFOURL</a> or <a href="config-reference.html#LINK_TARGET">TARGET</a> strings. This makes it easier to edit the configuration, and easier to make global changes if you move the server than runs the other system, for example.
134</p>
135<div class="example"><pre>
136<a href="config-reference.html#NODE_NODE">NODE</a> router_a
137 <a href="config-reference.html#NODE_LABEL">LABEL</a> Router A
138 <a href="config-reference.html#NODE_POSITION">POSITION</a> 100 200
139 <b>SET router_id 33</b>
140 <a href="config-reference.html#LINK_INFOURL">INFOURL</a> http://my.monitoring.system/view.php?id=<b>{node:this:router_id}</b>
141 <a href="config-reference.html#LINK_TARGET">TARGET</a> somemonitoringplugin:<b>{node:this:router_id}</b>
142</pre>
143</div>
144<p>Since information from these variables can also appear in the <a href="config-reference.html#LINK_NOTES">NOTES</a> popup for a <a href="config-reference.html#NODE_NODE">NODE</a> or <a href="config-reference.html#LINK_LINK">LINK,</a> then you can also use this as a more structured way to have that information in your config file, and still presented in the map.</p>
145<p>The second additional source is Data Source Plugins. Some plugins may define additional variables, above and beyond the normal 'in bandwidth' and 'out bandwidth' that they normally would. For example, the Cacti Host data source plugin returns a "bandwidth" that is actually a number representing the state of the device, according to Cacti - up, down, disabled, recovering. Since you might want to show this as text somewhere, or use it to change the icon for a device, it <em>also</em> defines an additional variable called 'state' that contains a string - 'up','down','recovering', or 'disabled'.</p>
146<p>
147Here is one more example, showing the use of relative node positions, node targets and tokens working together:
148<div class="example"><pre>
149 
150<a href="config-reference.html#NODE_NODE">NODE</a> fw_a
151 <a href="config-reference.html#NODE_POSITION">POSITION</a> 100 100
152 <a href="config-reference.html#NODE_LABEL">LABEL</a> Firewall A
153 <a href="config-reference.html#LINK_TARGET">TARGET</a> fw_a_cpu.rrd:cpu:- fw_a_sessions.rrd:-:sess
154 
155<a href="config-reference.html#NODE_NODE">NODE</a> fw_a_sessions
156 <a href="config-reference.html#NODE_POSITION">POSITION</a> fw_a -30 0
157 <a href="config-reference.html#NODE_LABEL">LABEL</a> {node:fw_a:outvalue} Sessions
158 </pre>
159</div>
160The first node uses two targets to populate the 'in' and 'out' slots from different RRD files. It uses the 'in' slot to change it's own color. The second node is positioned relative to the first, and uses tokens to show the number of sessions used (the 'out' slot) on the other node as it's label. In combination with the 'notes' available to plugins, you can display nearly anything in your weathermap.
161 
162</p>
163 
164 <h2><a name="plugins">Writing Plugins</a></h2>
165 <p>Version 0.9 of Weathermap introduces a plugin system for extending it's capabilities. This makes it possible for third parties to add new possible data sources and other functions to Weathermap without needing to alter the main code of the program.</p>
166 <p>Currently, there are two basic types of plugin - datasources and pre/post-processing. Datasource plugins allow you to add new <a href="config-reference.html#LINK_TARGET">TARGET</a> data sources. Pre-processing plugins are called once per map, before datasources are read, but after the map configuration is loaded. Post-processing plugins are called once per map, after all the data sources have been read. The processing plugins are intended to allow you to add additional information into the Map Notes data structure so that it can be accessed by the <a href="#tokens">special string tokens</a> in <a href="config-reference.html#NODE_NODE">NODE</a> labels, for example. </p>
167 <h3><a name="dataplugins">Datasource Plugins</a></h3>
168 <p>
169 Datasource plugins are the main plugin type in Weathermap. They allow the user to pull in data from almost any source, and incorporate it into the final Weathermap image. The best way to get started with writing a new DS plugin is probably to take an existing one apart.</p>
170 <p>
171 Each plugin is defined as a PHP class in the lib/datasources directory. The filename of the plugin must match the classname used inside the file. It's important to know that Weathermap <em>doesn't</em> instantiate the class - all the methods are just static methods in a convenient container.</p>
172 <p>Each plugin has three methods: Init, Recognise and ReadData.</p>
173 <p>At startup, Weathermap calls the Init method of each plugin to see if it can run at all. The Init method should check for
174 the availability of appropriate config, or PHP functions or files. It should then return TRUE or FALSE, to indicate if it can run or not. For example, the SNMP DS plugin returns FALSE if it can't find the snmp_get PHP function, which is normally due to the SNMP module not being configured with PHP.
175 </p>
176 <p>For each map, after the configuration file has been read, the ReadData function inside Weathermap process <a href="config-reference.html#LINK_TARGET">TARGET</a> lines to get data, before starting to draw the map. To do this, it loops though all the objects in the map, taking each <a href="config-reference.html#LINK_TARGET">TARGET</a> of each object in turn (objects can have multiple aggregated targets), and for each of the TARGETs, it calls all of the DS plugins' Recgonise method.
177 The Recognise method should return TRUE or FALSE, depending on if it thinks that the supplied <a href="config-reference.html#LINK_TARGET">TARGET</a> string is intended for it. This is normally decided by using preg_match to match a regular expression. It <em>should not</em> try and read any data source, or database, or file to validate the actual <a href="config-reference.html#LINK_TARGET">TARGET.</a> It should <em>only</em> decide if the <a href="config-reference.html#LINK_TARGET">TARGET</a> is the right 'shape' or not.</p>
178 <p>Recognise is called even for plugins that have previously returned FALSE for Init. This is so that Weathermap can tell the user that their <a href="config-reference.html#LINK_TARGET">TARGET</a> <em>would</em> have worked, if only the plugin was working OK, rather than mysteriously ignoring them.</p>
179 <p>Finally, once it has established which of the plugins should deal with the <a href="config-reference.html#LINK_TARGET">TARGET</a> string, it calls the ReadData method of that plugin, which should return a list() of three items - input value, output value and valid_time.</p> <p>The valid_time is a Unix time_t (as returned by time()), to indicate when the data was measured. This is mainly intended for things like RRDs where there may be a delay between the RRD being written and us reading the value, or for cached results. The input and output values are numeric, and are used as part of the final bandwidth values for the map object. If there is no valid result (e.g. the device id passed in the <a href="config-reference.html#LINK_TARGET">TARGET</a> string doesn't exist) then the plugin should return -1,-1 for those two values.</p>
180 <p>The ReadData function can also set addtional variables for the map object, which can then be used in strings in the map config file. It can do this by calling the $map->add_note() function.</p>
181 <p>It can also <em>receive</em> addtional parameters that the user has defined with <a href="config-reference.html#GLOBAL_SET">SET</a> commands in the map config file. This is mainly intended for things like hostnames for the remote system that data is being read from, so that they don't have to be hardcoded, or appear in <em>every</em> <a href="config-reference.html#LINK_TARGET">TARGET</a> string.</p>
182 <h3><a name="prepostplugins">Pre- &amp; Post-Processing Plugins</a></h3>
183 <p>Post-processing plugins can be used to calculate additional global statistics for a map, which can then be used in elements on the map. For example, you could calculate an average latency across all links in the network, or a total network uptime based on the uptimes of all nodes. Currently, there aren't any of these plugins, but the hooks are available.</p>
184 </div>
185</body>
186</html>

Powered by WebSVN 2.2.1