Skip to content

Normalize and Cleanup Code #16

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

Merged
merged 4 commits into from
Nov 22, 2024
Merged
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
4 changes: 2 additions & 2 deletions application/controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public function indexAction()
$this->redirectNow(Url::fromPath('grafana/icingadbdashboard')->setQueryString($this->params));
}

$this->getTabs()->add('graphs', array(
$this->getTabs()->add('graphs', [
'active' => true,
'label' => $this->translate('Graphs'),
'url' => $this->getRequest()->getUrl()
));
]);

$hostname = $this->params->getRequired('host');
$servicename = $this->params->get('service');
Expand Down
55 changes: 30 additions & 25 deletions application/controllers/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,23 @@ public function init()
*/
public function indexAction()
{
/*
$this->getTabs()->add('graphs', array(
'active' => true,
'label' => $this->translate('Graphs'),
'url' => $this->getRequest()->getUrl()
));
$this->view->graphs = $this->Config('graphs');
*/
$this->view->tabs = $this->Module()->getConfigTabs()->activate('graph');
$this->view->graphs = $this->Config('graphs');
}

/**
* Add a new graph
*/
public function newAction()
{
$this->getTabs()->add('new-graph', array(
'active' => true,
'label' => $this->translate('New Graph'),
'url' => $this->getRequest()->getUrl()
));
$this->getTabs()->add('new-graph', [
'active' => true,
'label' => $this->translate('New Graph'),
'url' => $this->getRequest()->getUrl()
]);

$graphs = new GraphForm();

$graphs
->setIniConfig($this->Config('graphs'))
->setRedirectUrl('grafana/graph')
Expand All @@ -54,20 +49,23 @@ public function newAction()
public function removeAction()
{
$graph = $this->params->getRequired('graph');
$this->getTabs()->add('remove-graph', array(
'active' => true,
'label' => $this->translate('Remove Graph'),
'url' => $this->getRequest()->getUrl()
));
$this->getTabs()->add('remove-graph', [
'active' => true,
'label' => $this->translate('Remove Graph'),
'url' => $this->getRequest()->getUrl()
]);

$graphs = new GraphForm();

try {
$graphs
->setIniConfig($this->Config('graphs'))
->bind($graph);
} catch (NotFoundError $e) {
$this->httpNotFound($e->getMessage());
}
$confirmation = new ConfirmRemovalForm(array(

$confirmation = new ConfirmRemovalForm([
'onSuccess' => function (ConfirmRemovalForm $confirmation) use ($graph, $graphs) {
$graphs->remove($graph);
if ($graphs->save()) {
Expand All @@ -76,35 +74,42 @@ public function removeAction()
}
return false;
}
));
]);

$confirmation
->setRedirectUrl('grafana/graph')
->setSubmitLabel($this->translate('Remove Graph'))
->handleRequest();

$this->view->form = $confirmation;
}

/**
* Update a graph
*/
public function updateAction()
{
$graph = $this->params->getRequired('graph');
$this->getTabs()->add('update-graph', array(
'active' => true,
'label' => $this->translate('Update Graph'),
'url' => $this->getRequest()->getUrl()
));
$this->getTabs()->add('update-graph', [
'active' => true,
'label' => $this->translate('Update Graph'),
'url' => $this->getRequest()->getUrl()
]);

$graphs = new GraphForm();

try {
$graphs
->setIniConfig($this->Config('graphs'))
->bind($graph);
} catch (NotFoundError $e) {
$this->httpNotFound($e->getMessage());
}

$graphs
->setRedirectUrl('grafana/graph')
->handleRequest();

$this->view->form = $graphs;
}
}
2 changes: 2 additions & 0 deletions application/controllers/IcingadbdashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public function indexAction()
}

$this->applyRestrictions($query);

$object = $query->first();

if ($object === null) {
throw new NotFoundError(t('Host or Service not found'));
}
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/IcingadbimgController.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)

// fetch image with curl
$curl_handle = curl_init();
$curl_opts = array(
$curl_opts = [
CURLOPT_URL => $pngUrl,
CURLOPT_CONNECTTIMEOUT => 2,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => $this->SSLVerifyPeer,
CURLOPT_SSL_VERIFYHOST => ($this->SSLVerifyHost) ? 2 : 0,
CURLOPT_TIMEOUT => $this->proxyTimeout,
);
];

if ($this->authentication == "token") {
$curl_opts[CURLOPT_HTTPHEADER] = [
Expand Down
22 changes: 3 additions & 19 deletions application/controllers/IcingadbshowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Icinga\Module\Grafana\ProvidedHook\Icingadb\HostDetailExtension;
use Icinga\Module\Grafana\ProvidedHook\Icingadb\ServiceDetailExtension;
use Icinga\Module\Grafana\Web\Controller\IcingadbGrafanaController;
use Icinga\Module\Grafana\Web\Widget\PrintAction;
use Icinga\Module\Icingadb\Model\CustomvarFlat;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\Service;
Expand All @@ -16,14 +15,13 @@
use ipl\Html\HtmlElement;
use ipl\Html\HtmlString;
use ipl\Stdlib\Filter;
use ipl\Web\Url;

class IcingadbshowController extends IcingadbGrafanaController
{
/** @var bool */
protected $showFullscreen;
protected $host;
protected $custvardisable = "grafana_graph_disable";
protected $custvardisable = 'grafana_graph_disable';
protected $config;
protected $object;

Expand All @@ -45,20 +43,6 @@ public function indexAction()
{
$this->disableAutoRefresh();

/*
if (!$this->showFullscreen) {
$this->getTabs()->add(
'graphs',
[
'label' => $this->translate('Grafana Graphs'),
'url' => $this->getRequest()->getUrl()
]
)->activate('graphs');

$this->getTabs()->extend(new PrintAction());
}
*/

$this->addControl(
HtmlElement::create(
'h1',
Expand Down Expand Up @@ -133,7 +117,7 @@ public function indexAction()
}


public function getHostObject($host)
public function getHostObject(string $host): Host
{
$query = Host::on($this->getDb())->with(['state', 'icon_image']);
$query->filter(Filter::equal('name', $host));
Expand All @@ -147,7 +131,7 @@ public function getHostObject($host)
return $host;
}

public function getServiceObject($service, $host)
public function getServiceObject(string $service, string $host): Service
{
$query = Service::on($this->getDb());

Expand Down
Loading