Skip to content

Commit

Permalink
Remove old Grafana version everywhere, fixes #267
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikesch-mp committed May 3, 2021
1 parent 2cae443 commit f22dd76
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 84 deletions.
4 changes: 0 additions & 4 deletions application/controllers/GraphController.php
Expand Up @@ -14,7 +14,6 @@ class GraphController extends Controller
public function init()
{
$this->assertPermission('grafana/graphconfig');
$this->view->grafanaVersion = $this->Config()->get('grafana', 'version');
}

/**
Expand Down Expand Up @@ -47,7 +46,6 @@ public function newAction()
$graphs
->setIniConfig($this->Config('graphs'))
->setRedirectUrl('grafana/graph')
->setGrafanaVersion($this->view->grafanaVersion)
->handleRequest();
$this->view->form = $graphs;
}
Expand Down Expand Up @@ -101,14 +99,12 @@ public function updateAction()
try {
$graphs
->setIniConfig($this->Config('graphs'))
->setGrafanaVersion($this->view->grafanaVersion)
->bind($graph);
} catch (NotFoundError $e) {
$this->httpNotFound($e->getMessage());
}
$graphs
->setRedirectUrl('grafana/graph')
->setGrafanaVersion($this->view->grafanaVersion)
->handleRequest();
$this->view->form = $graphs;
}
Expand Down
70 changes: 20 additions & 50 deletions application/controllers/ImgController.php
Expand Up @@ -43,7 +43,6 @@ class ImgController extends MonitoringAwareController
protected $SSLVerifyPeer = false;
protected $SSLVerifyHost = "0";
protected $cacheTime;
protected $grafanaVersion = "0";
protected $defaultdashboarduid;
protected $refresh = "yes";

Expand All @@ -68,7 +67,6 @@ public function init()

/* load global configuration */
$this->myConfig = Config::module('grafana')->getSection('grafana');
$this->grafanaVersion = $this->myConfig->get('version', $this->grafanaVersion);
$this->grafanaHost = $this->myConfig->get('host', $this->grafanaHost);
if ($this->grafanaHost == null) {
throw new ConfigurationError(
Expand All @@ -79,7 +77,7 @@ public function init()

$this->defaultDashboard = $this->myConfig->get('defaultdashboard', $this->defaultDashboard);
$this->defaultdashboarduid = $this->myConfig->get('defaultdashboarduid', NULL);
if ($this->grafanaVersion == "1" && is_null($this->defaultdashboarduid)) {
if (is_null($this->defaultdashboarduid)) {
throw new ConfigurationError(
'Usage of Grafana 5 is configured but no UID for default dashboard found!'
);
Expand Down Expand Up @@ -277,12 +275,7 @@ private function setGraphConf($serviceName, $serviceCommand = NULL)
}

$this->dashboard = $graphConfig->get($serviceName, 'dashboard', $this->defaultDashboard);
if ($this->grafanaVersion == "1")
{
$this->dashboarduid = $graphConfig->get($serviceName, 'dashboarduid', $this->defaultdashboarduid);
} else {
$this->dashboardstore = $graphConfig->get($serviceName, 'dashboardstore', $this->defaultDashboardStore);
}
$this->dashboarduid = $graphConfig->get($serviceName, 'dashboarduid', $this->defaultdashboarduid);
$this->panelId = $this->hasParam('panelid') ? $this->getParam('panelid') : $graphConfig->get($serviceName, 'panelId', $this->defaultDashboardPanelId);
$this->orgId = $graphConfig->get($serviceName, 'orgId', $this->defaultOrgId);
$this->customVars = $graphConfig->get($serviceName, 'customVars', '');
Expand All @@ -298,47 +291,24 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
$imageHtml = $this->translate('CURL extension is missing. Please install CURL for PHP and ensure it is loaded.');
return false;
}
if ($this->grafanaVersion == "1")
{
$this->pngUrl = sprintf(
'%s://%s/render/d-solo/%s/%s?var-hostname=%s&var-service=%s&var-command=%s%s&panelId=%s&orgId=%s&width=%s&height=%s&theme=%s&from=%s&to=%s',
$this->protocol,
$this->grafanaHost,
$this->dashboarduid,
$this->dashboard,
rawurlencode($hostName),
rawurlencode($serviceName),
rawurlencode($this->object->check_command),
$this->customVars,
$this->panelId,
$this->orgId,
$this->width,
$this->height,
$this->grafanaTheme,
urlencode($this->timerange),
urlencode($this->timerangeto)
);
} else {

$this->pngUrl = sprintf(
'%s://%s/render/dashboard-solo/%s/%s?var-hostname=%s&var-service=%s&var-command=%s%s&panelId=%s&orgId=%s&width=%s&height=%s&theme=%s&from=%s&to=%s',
$this->protocol,
$this->grafanaHost,
$this->dashboardstore,
$this->dashboard,
rawurlencode($hostName),
rawurlencode($serviceName),
rawurlencode($this->object->check_command),
$this->customVars,
$this->panelId,
$this->orgId,
$this->width,
$this->height,
$this->grafanaTheme,
urlencode($this->timerange),
urlencode($this->timerangeto)
);
}
$this->pngUrl = sprintf(
'%s://%s/render/d-solo/%s/%s?var-hostname=%s&var-service=%s&var-command=%s%s&panelId=%s&orgId=%s&width=%s&height=%s&theme=%s&from=%s&to=%s',
$this->protocol,
$this->grafanaHost,
$this->dashboarduid,
$this->dashboard,
rawurlencode($hostName),
rawurlencode($serviceName),
rawurlencode($this->object->check_command),
$this->customVars,
$this->panelId,
$this->orgId,
$this->width,
$this->height,
$this->grafanaTheme,
urlencode($this->timerange),
urlencode($this->timerangeto)
);

// fetch image with curl
$curl_handle = curl_init();
Expand Down
36 changes: 11 additions & 25 deletions application/forms/Graph/GraphForm.php
Expand Up @@ -58,18 +58,15 @@ public function createElements(array $formData)
)
);

if($this->grafanaVersion == "1")
{
$this->addElement(
'text',
'dashboarduid',
array(
'label' => $this->translate('Dashboard UID'),
'description' => $this->translate('UID of the dashboard.'),
'required' => true,
)
);
}
$this->addElement(
'text',
'dashboarduid',
array(
'label' => $this->translate('Dashboard UID'),
'description' => $this->translate('UID of the dashboard.'),
'required' => true,
)
);

$this->addElement(
'text',
Expand Down Expand Up @@ -196,13 +193,9 @@ public function onSuccess()
'height' => $this->getElement('height')->getValue(),
'width' => $this->getElement('width')->getValue(),
'repeatable' => $this->getElement('repeatable')->getValue(),
'nmetrics' => $this->getElement('nmetrics')->getValue()
'nmetrics' => $this->getElement('nmetrics')->getValue(),
'dashboarduid' => $this->getElement('dashboarduid')->getValue()
);
if($this->grafanaVersion == "1")
{
$values['dashboarduid'] = $this->getElement('dashboarduid')->getValue();
}


if (empty($values['timerange']))
{
Expand Down Expand Up @@ -343,11 +336,4 @@ public function update($name, array $values, $oldName)
}
return $this;
}

public function setGrafanaVersion ($version = "0")
{
$this->grafanaVersion = $version;
return $this;
}

}
6 changes: 1 addition & 5 deletions application/views/scripts/graph/index.phtml
Expand Up @@ -21,9 +21,7 @@
<tr>
<th><?= $this->translate('Name') ?></th>
<th><?= $this->translate('Dashboard') ?></th>
<?php if ($this->grafanaVersion == "1"): ?>
<th><?= $this->translate('Dashboard UID') ?></th>
<?php endif ?>
<th><?= $this->translate('Dashboard UID') ?></th>
<th><?= $this->translate('PanelID') ?></th>
<th><?= $this->translate('CustomVars') ?></th>
<th><?= $this->translate('Timerange') ?></th>
Expand All @@ -46,9 +44,7 @@
) ?>
</td>
<td><?= $this->escape($graph->dashboard) ?></td>
<?php if ($this->grafanaVersion == "1"): ?>
<td><?= $this->escape($graph->dashboarduid) ?></td>
<?php endif ?>
<td><?= $this->escape($graph->panelId) ?></td>
<td><?= isset($graph->customVars) ? "Yes" : "No" ?></td>
<td><?= $this->escape($graph->timerange) ?></td>
Expand Down

0 comments on commit f22dd76

Please sign in to comment.