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 link when using iframes to have iframes without using the grafana-renderer and still have links to Grafana #300

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 25 additions & 14 deletions application/forms/Config/GeneralConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function createElements(array $formData)
);
}

if (isset($formData['grafana_accessmode']) && ( $formData['grafana_accessmode'] != 'iframe' )) {
if (isset($formData['grafana_accessmode'])) {
$this->addElement(
'number',
'grafana_height',
Expand All @@ -271,15 +271,26 @@ public function createElements(array $formData)
'description' => $this->translate('The default graph height in pixels.')
)
);
$this->addElement(
'number',
'grafana_width',
array(
'value' => '640',
'label' => $this->translate('Graph width'),
'description' => $this->translate('The default graph width in pixels.')
)
);
if ( $formData['grafana_accessmode'] != 'iframe' ) {
$this->addElement(
'number',
'grafana_width',
array(
'value' => '640',
'label' => $this->translate('Graph width'),
'description' => $this->translate('The default graph width in pixels.')
)
);
}
}

if (isset($formData['grafana_accessmode'])) {
if ($formData['grafana_accessmode'] === 'indirectproxy') {
$desc = 'Image is a link to the dashboard on the Grafana server.';
}
else {
$desc = 'Above image is a link to the dashboard on the Grafana server.';
}
$this->addElement(
'select',
'grafana_enableLink',
Expand All @@ -290,12 +301,12 @@ public function createElements(array $formData)
'yes' => $this->translate('Yes'),
'no' => $this->translate('No'),
),
'description' => $this->translate('Image is an link to the dashboard on the Grafana server.'),
'description' => $this->translate($desc),
'class' => 'autosubmit'
)
);
}
if (isset($formData['grafana_enableLink']) && ( $formData['grafana_enableLink'] === 'yes') && ( $formData['grafana_accessmode'] != 'iframe' )) {
if (isset($formData['grafana_enableLink']) && ( $formData['grafana_enableLink'] === 'yes')) {
$this->addElement(
'select',
'grafana_usepublic',
Expand All @@ -311,7 +322,7 @@ public function createElements(array $formData)
)
);
}
if (isset($formData['grafana_usepublic']) && ( $formData['grafana_usepublic'] === 'yes' ) && ( $formData['grafana_accessmode'] != 'iframe' )) {
if (isset($formData['grafana_usepublic']) && ( $formData['grafana_usepublic'] === 'yes' )) {
$this->addElement(
'text',
'grafana_publichost',
Expand Down Expand Up @@ -345,4 +356,4 @@ public function createElements(array $formData)
)
);
}
}
}
10 changes: 6 additions & 4 deletions library/Grafana/ProvidedHook/Grapher.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private function getMyPreviewHtml($serviceName, $hostName, &$previewHtml)

);
} elseif ($this->accessMode == "iframe") {
$iframehtml = '<iframe src="%s://%s/d-solo/%s/%s?var-hostname=%s&var-service=%s&var-command=%s%s&panelId=%s&orgId=%s&theme=%s&from=%s&to=%s" alt="%s" height="%d" frameBorder="0" style="width: 100%%;"></iframe>';
$iframehtml = '<iframe src="%s://%s/d-solo/%s/%s?var-hostname=%s&var-service=%s&var-command=%s%s&panelId=%s&orgId=%s&theme=%s&from=%s&to=%s&refresh=5m" alt="%s" height="%d" frameBorder="0" style="width: 100%%"></iframe>';
$previewHtml = sprintf(
$iframehtml,
$this->protocol,
Expand Down Expand Up @@ -377,8 +377,10 @@ public function getPreviewHtml(MonitoredObject $object, $report = false)
if (!$res || $this->enableLink == "no" || !$this->permission->hasPermission('grafana/enablelink')) {
$html .= $previewHtml;
} else {

$html .= '<a href="%s://%s/d/%s/%s?var-hostname=%s&var-service=%s&var-command=%s%s&from=%s&to=%s&orgId=%s&viewPanel=%s" target="_blank">%s</a>';
if ($this->accessMode == "iframe") {
$previewHtml = " => see in Grafana</a>" . $previewHtml;
}
$html .= '<a href="%s://%s/d/%s/%s?var-hostname=%s&var-service=%s&var-command=%s%s&from=%s&to=%s&orgId=%s&viewPanel=%s" target="_blank" style="width: 100%%">%s';

$html = sprintf(
$html,
Expand Down Expand Up @@ -444,6 +446,6 @@ public function getPreviewHtml(MonitoredObject $object, $report = false)
$return_html .= " </tbody></table>";

}
return '<div class="icinga-module module-grafana" style="display: inline-block;">' . $this->title . $menu . $return_html . '</div>';
return '<div class="icinga-module module-grafana" style="display: inline-block; width: 100%;">' . $this->title . $menu . $return_html . '</div>';
}
}