Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new filters to apply dashboards #273

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions application/forms/Graph/GraphForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ public function createElements(array $formData)
)
);

$this->addElement(
'text',
'serviceFilter',
array(
'description' => $this->translate(
'Use the dashboard if the filter matches the service name. (String or RegEx) '
. '(Examples: "disk.*" or "disk /var/(log|lib).*")'
),
'label' => $this->translate('Service filter'),
'required' => false
)
);

$this->addElement(
'text',
'commandFilter',
array(
'description' => $this->translate(
'Use the dashboard if the filter matches the check_command. (String or RegEx)'
),
'label' => $this->translate('Command filter'),
'required' => false
)
);

$this->addElement(
'text',
'dashboard',
Expand Down Expand Up @@ -185,6 +210,8 @@ public function onSuccess()
{
$name = $this->getElement('name')->getValue();
$values = array(
'serviceFilter' => $this->getElement('serviceFilter')->getValue(),
'commandFilter' => $this->getElement('commandFilter')->getValue(),
'dashboard' => $this->getElement('dashboard')->getValue(),
'panelId' => $this->getElement('panelId')->getValue(),
'orgId' => $this->getElement('orgId')->getValue(),
Expand All @@ -197,6 +224,12 @@ public function onSuccess()
'dashboarduid' => $this->getElement('dashboarduid')->getValue()
);

if (empty($values['serviceFilter'])) {
$values['serviceFilter'] = null;
}
if (empty($values['commandFilter'])) {
$values['commandFilter'] = null;
}
if (empty($values['timerange']))
{
$values['timerange'] = null;
Expand Down
4 changes: 4 additions & 0 deletions application/views/scripts/graph/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<thead>
<tr>
<th><?= $this->translate('Name') ?></th>
<th><?= $this->translate('Service filter') ?></th>
<th><?= $this->translate('Command filter') ?></th>
<th><?= $this->translate('Dashboard') ?></th>
<th><?= $this->translate('Dashboard UID') ?></th>
<th><?= $this->translate('PanelID') ?></th>
Expand All @@ -43,6 +45,8 @@
array('title' => sprintf($this->translate('Update Grafana graph %s'), $name))
) ?>
</td>
<td><?= $this->escape($graph->serviceFilter) ?></td>
<td><?= $this->escape($graph->commandFilter) ?></td>
<td><?= $this->escape($graph->dashboard) ?></td>
<td><?= $this->escape($graph->dashboarduid) ?></td>
<td><?= $this->escape($graph->panelId) ?></td>
Expand Down
34 changes: 26 additions & 8 deletions library/Grafana/ProvidedHook/Grapher.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,34 @@ private function getGraphConf($serviceName, $serviceCommand = null)

$this->graphConfig = Config::module('grafana', 'graphs');

if ($this->graphConfig->hasSection(strtok($serviceName,
' ')) && ($this->graphConfig->hasSection($serviceName) == false)) {
$serviceName = strtok($serviceName, ' ');
$selectedSectionName = null;
foreach ($this->graphConfig->keys() as $sectionName) {
$serviceFilter = $this->getGraphConfigOption($sectionName, 'serviceFilter');
$commandFilter = $this->getGraphConfigOption($sectionName, 'commandFilter');
if ($serviceFilter == null && $commandFilter == null) {
continue;
}
if (($serviceFilter == null || preg_match('/' . $serviceFilter . '/', $serviceName)) &&
($commandFilter == null || preg_match('/' . $commandFilter . '/', $serviceCommand))) {
$selectedSectionName = $sectionName;
break;
}
}
if ($this->graphConfig->hasSection(strtok($serviceName,
' ')) == false && ($this->graphConfig->hasSection($serviceName) == false)) {
$serviceName = $serviceCommand;
if ($this->graphConfig->hasSection($serviceCommand) == false && $this->defaultDashboard == 'none') {
return null;

if ($selectedSectionName == null) {
if ($this->graphConfig->hasSection(strtok($serviceName,
' ')) && ($this->graphConfig->hasSection($serviceName) == false)) {
$serviceName = strtok($serviceName, ' ');
}
if ($this->graphConfig->hasSection(strtok($serviceName,
' ')) == false && ($this->graphConfig->hasSection($serviceName) == false)) {
$serviceName = $serviceCommand;
if ($this->graphConfig->hasSection($serviceCommand) == false && $this->defaultDashboard == 'none') {
return null;
}
}
} else {
$serviceName = $selectedSectionName;
}

$this->dashboard = $this->getGraphConfigOption($serviceName, 'dashboard', $this->defaultDashboard);
Expand Down