Skip to content

Commit

Permalink
Configure graph as link.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikesch-mp committed Feb 8, 2017
1 parent 019e3fb commit 183c43e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
28 changes: 9 additions & 19 deletions README.md
Expand Up @@ -7,8 +7,10 @@ Insert Grafana graphs into Icinga Web 2 to display performance metrics.
## Requirements

Icinga Web 2 (>= 2.4.0)

Grafana (>= 4.1)
InfluxDB

InfluxDB or any other valid data source

## Installation

Expand All @@ -23,54 +25,42 @@ Import the 2 json files into your Grafana server. The default dashboard must be
There are various configuration settings to tweak how the module behaves.

**Username**

*(Optional)* The HTTP Basic Auth user name used to access Grafana.

**Password**

*(Optional)* The HTTP Basic Auth password used to access Grafana. You need to set username too.

**Host**

*(Required)* The Grafana server host name (and port).

**Protocol**

The protocol used to access the Grafana server, default: *http*

**Graph height**

The graph height in pixel, default: *280*

**Graph width**

The graph width in pixel, default : *640*

**Timerange now-**

The global time range for the graphs, default: *6h*
The global time range for the graphs, default: *6h'

## Graph configuration

**Name of Service**

*(Required)* The name (not display name) of the service which you want to configure a graph for.
If you parametrized services, for example 'disk /data', you can use 'disk' as servicename, so
all disk checks get same graph. If you configure graphs 'disk' and one for 'disk /somedir',
the service 'disk /somedir' will use the graph configured in 'disk /somedir'.
The name (not display name) of the service which you want to configure a graph for.

**Dashboard name**

*(Required)* The name of the Grafana dashboard to use.
The name of the Grafana dashboard to use.

**PanelId**

*(Required)* The panelId of the graph. You can get if if you click on "share" at the graph title.
The panelId of the graph. You can get if if you click on "share" at the graph title.

**Timerange now-**

The time range for this service graph only.

**Enable link**
Enables the perfdata image as an link to the Grafana dashboard.

## Hats off to

Expand Down
15 changes: 5 additions & 10 deletions application/forms/Config/GeneralConfigForm.php
Expand Up @@ -98,23 +98,18 @@ public function createElements(array $formData)
'description' => $this->translate('Timerange to use for the graphs.')
)
);
/**
$this->addElement(
'select',
'grafana_use_nrpe_command',
'grafana_enableLink',
array(
'label' => $this->translate('Use nrpe_command'),
'label' => $this->translate('Enable link'),
'multiOptions' => array(
'true' => $this->translate('True'),
'false' => $this->translate('False'),
'yes' => $this->translate('Yes'),
'no' => $this->translate('No'),
),
'description' => $this->translate(
'Use nrpe_command instead of check_command as measurements.'
. 'See README on how to configure Icinga2 to use nrpe_command in InfluxdbWriter feature.'
)
'description' => $this->translate('Image is an link to the dashboard on the Grafana server.')
)
);
**/
}
}

7 changes: 7 additions & 0 deletions library/Grafana/Grapher.php
Expand Up @@ -24,6 +24,7 @@ class Grapher extends GrapherHook
protected $timerange = "6h";
protected $username = null;
protected $width = 640;
protected $enableLink = true;

protected function init()
{
Expand All @@ -40,6 +41,7 @@ protected function init()
$this->timerange = $this->config->get('timerange', $this->timerange);
$this->height = $this->config->get('height', $this->height);
$this->width = $this->config->get('width', $this->width);
$this->enableLink = $this->config->get('enableLink', $this->enableLink);

if($this->username != null){
if($this->password != null){
Expand Down Expand Up @@ -128,6 +130,11 @@ public function getPreviewHtml(MonitoredObject $object)

$this->getGraphConf($serviceName);

if ($this->enableLink == "no")
{
return $this->getPreviewImage($serviceName, $hostName);
}

$html = '<a href="%s://%s/dashboard/db/%s?var-hostname=%s&var-service=%s&from=now-%s&to=now';

if ( $this->dashboard != "icinga2-default")
Expand Down

0 comments on commit 183c43e

Please sign in to comment.