Skip to content

Commit a3d1345

Browse files
Merge pull request #1 from amousset/master
Upgrade
2 parents 4398753 + 476d3a5 commit a3d1345

File tree

3 files changed

+12
-126
lines changed

3 files changed

+12
-126
lines changed

README.md

+2-117
Original file line numberDiff line numberDiff line change
@@ -12,124 +12,9 @@ The plugins requires:
1212

1313
Copy the content of the `lib` folder into the `lib` folder of your PHP Weathermap installation.
1414

15-
## Configuration
15+
## Documentation
1616

17-
### Configuration of the new datasource for traffic
18-
19-
You have to configure the following parameters in your weathermap file global settings:
20-
21-
---
22-
23-
`SET zabbix_user username`
24-
25-
Zabbix username you want to connect with.
26-
27-
---
28-
29-
`SET zabbix_password password`
30-
31-
Zabbix password for the given user, you can connect with a `guest` account by ommitting this parameter.
32-
33-
---
34-
35-
`SET zabbix_url http://zabbix/zabbix/api_jsonrpc.php`
36-
37-
The Zabbix API URL used to make requests.
38-
39-
---
40-
41-
To configure a link, use the following `TARGET` syntax:
42-
43-
```
44-
TARGET zabbix:keyname:hostname:input_item_name:output_item_name
45-
```
46-
47-
with:
48-
49-
* `keyname`: the attribute you want to use to select items in the configuration, possible values:
50-
** `name` refers to the item name configured in Zabbix
51-
** `key_` refers to the key configured in Zabbix
52-
** `itemid` refers to the item id used by Zabbix
53-
* `hostname`: the hostname of the host you want to use
54-
* `input_item_name`: the input item identifier (according to what you put as keyname)
55-
* `output_item_name`: the output item identifier (according to what you put as keyname)
56-
57-
For example:
58-
59-
```
60-
TARGET zabbix:name:switch-01:GigabitEthernet3/8-IN:GigabitEthernet3/8-OUT
61-
```
62-
63-
### Configuration of the Zabbix graphs integration
64-
65-
You have to configure the following parameters in yoour weathermap file:
66-
67-
---
68-
69-
`SET post_zabbix_graphs 1`
70-
71-
Enable the Zabbix integration for overlib graphs, using a specific `OVERLIBGRAPH` syntax.
72-
73-
---
74-
75-
`SET post_zabbix_graph_links 1`
76-
77-
Enable the links to the graph page in Zabbix, overriding the `INFOURL` links with link to a Zabbix graph.
78-
79-
---
80-
81-
`SET post_zabbix_graph_base_url https://zabbix/zabbix`
82-
83-
The URL to the Zabbix frontend used to generate the graphs links.
84-
85-
---
86-
87-
`SET post_zabbix_graph_width 420`
88-
89-
The graphs width in pixels, use `OVERLIBWIDTH` to improve the positionning of the popup image. This is the width of the actual graph, and the image will be larger.
90-
91-
---
92-
93-
`SET post_zabbix_graph_height 150`
94-
95-
The graph height in pixels, use `OVERLIBHEIGHT` to improve the positionning of the popup image. This is the height of the actual graph, and the image will be larger.
96-
97-
---
98-
99-
`SET post_zabbix_graph_period 86400`
100-
101-
The graph period in seconds.
102-
103-
---
104-
105-
To configure a graph, use the following `OVERLIBGRAPH` syntax, for nodes and links:
106-
107-
```
108-
OVERLIBGRAPH zabbix:hostname:graph_name
109-
```
110-
111-
with:
112-
113-
* `keyname`: the attribute you want to use to select items in the configuration, possible values:
114-
** `name` refers to the graph name configured in Zabbix
115-
** `graphid` refers to the graph is used by Zabbix
116-
* `hostname`: the hostname of the host you want to use
117-
* `graph_name`: the graph identifier (according to what you put as keyname)
118-
119-
For example:
120-
121-
```
122-
OVERLIBGRAPH zabbix:switch-01:GigabitEthernet3/8
123-
```
124-
125-
It can also be used with `INOVERLIBGRAPH` and `OUTOVERLIBGRAPH` (for links only):
126-
127-
```
128-
INOVERLIBGRAPH zabbix:name:switch-01:GigabitEthernet3/8-IN
129-
OUTOVERLIBGRAPH zabbix:name:switch-01:GigabitEthernet3/8-OUT
130-
```
131-
132-
The generated `INFOURL` will be a link to the configured graph in your Zabbix frontend.
17+
A complete documentation is available on the project [wiki](https://github.com/amousset/php-weathermap-zabbix-plugin/wiki).
13318

13419
## TODO
13520

lib/datasources/WeatherMapDataSource_zabbix.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Init(&$map)
1818

1919
function Recognise($targetstring)
2020
{
21-
if(preg_match("/^zabbix:([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+)$/", $targetstring, $matches))
21+
if(preg_match("/^zabbix:([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\],]+):([-a-zA-Z0-9_\.\/\[\],]+)$/", $targetstring, $matches))
2222
{
2323
return true;
2424
}
@@ -34,7 +34,7 @@ function ReadData($targetstring, &$map, &$item)
3434
$data[OUT] = null;
3535
$data_time = 0;
3636

37-
if(preg_match("/^zabbix:([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+)$/", $targetstring, $matches))
37+
if(preg_match("/^zabbix:([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\],]+):([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\],]+)$/", $targetstring, $matches))
3838
{
3939
$zabbix_uri = $map->get_hint('zabbix_uri');
4040

@@ -45,8 +45,9 @@ function ReadData($targetstring, &$map, &$item)
4545

4646
wm_debug ("Zabbix ReadData: Found (".$host.",".$in.",".$out.")\n");
4747

48-
$in_value = $this->zabbixApi->getItemLastValue($host, $zabbix_key, $in)["lastvalue"];
4948
$raw_out_value = $this->zabbixApi->getItemLastValue($host, $zabbix_key, $out);
49+
$raw_in_value = $this->zabbixApi->getItemLastValue($host, $zabbix_key, $in);
50+
$in_value = $raw_in_value["lastvalue"];
5051
$out_value = $raw_out_value["lastvalue"];
5152
$data_time = $raw_out_value["lastclock"];
5253

lib/post/WeatherMapPostProcessorZabbix.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class WeatherMapPostProcessorZabbix extends WeatherMapPostProcessor
3+
class WeatherMapPostProcessorZabbix extends WeatherMapPostProcessor
44
{
55
function run(&$map)
66
{
@@ -17,11 +17,11 @@ function run(&$map)
1717
$graphPeriod = $map->get_hint('post_zabbix_graph_period');
1818

1919
foreach (array_merge($map->links, $map->nodes) as $item) {
20-
foreach (range(0, 1) as $k) {
20+
foreach (range(0, 1) as $k) { // IN and OUT, if necessary
2121
$graph = $item->overliburl[$k];
2222

23-
if (count($graph) == 1) {
24-
if(preg_match('/^zabbix:([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+)$/', $graph[0], $matches))
23+
foreach ($graph as $index=>$graphItem) {
24+
if(preg_match('/^zabbix:([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+):([-a-zA-Z0-9_\.\/\[\]]+)$/', $graphItem, $matches))
2525
{
2626
$keyname = $matches[1];
2727
$host = $matches[2];
@@ -31,10 +31,10 @@ function run(&$map)
3131

3232
$graphId = $this->zabbixApi->getGraphId($host, $keyname, $key);
3333
if (isset($graphId)) {
34-
if ($addGraphLink) {
34+
if ($addGraphLink) {
3535
$item->infourl[$k] = $baseUrl.'/charts.php?form_refresh=1&fullscreen=0&graphid='.$graphId;
3636
}
37-
$item->overliburl[$k][0] = $baseUrl.'/chart2.php?width='.$graphWidth.'&height='.
37+
$item->overliburl[$k][$index] = $baseUrl.'/chart2.php?width='.$graphWidth.'&height='.
3838
$graphHeight.'&period='.$graphPeriod.'&stime=now&graphid='.$graphId;
3939
}
4040
}

0 commit comments

Comments
 (0)