Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 0f36979

Browse files
Merge pull request #54 from pajavyskocil/nagios_status
Added page showing status of selected components
2 parents f2b0c72 + 545a5f1 commit 0f36979

File tree

8 files changed

+390
-0
lines changed

8 files changed

+390
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44
## [Unreleased]
55
[Added]
66
- List of services is displayed as JSON if parameter 'output=json' is set in URL
7+
- Page showing status of selected components
8+
- This page is also available in JSON format if parameter 'output=json' is set in URL
79

810
[Changed]
911
- Updated composer.json dependencies

config-templates/module_perun.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,59 @@
5151
*/
5252
'disco.removeAuthnContextClassRefPrefix' => 'urn:cesnet:proxyidp:',
5353

54+
/**
55+
*****************************************
56+
* Part of configuration for status page *
57+
*****************************************
58+
*/
59+
60+
/**
61+
* Specify the used interface to get the status data
62+
* Only NAGIOS type is now allowed
63+
*/
64+
'status.type' => 'NAGIOS',
65+
66+
/**
67+
* Specify the url for get status information
68+
*/
69+
'status.nagios.url' => '',
70+
71+
/**
72+
* Specify the path to the certicate
73+
*/
74+
'status.nagios.certificate_path' => '',
75+
76+
/**
77+
* Specify the CA dir path
78+
*/
79+
'status.nagios.ca_path' => '/etc/ssl/certs',
80+
81+
/**
82+
* Specify the password for private key
83+
*
84+
* OPTIONAL
85+
*/
86+
'status.nagios.certificate_password' => '',
87+
88+
/**
89+
* Specify, if the peer verification is enabled,
90+
*
91+
* OPTIONAL
92+
* Default: false
93+
*/
94+
'status.nagios.peer_verification' => false,
95+
96+
/**
97+
* Specify the list of services, which will be shown
98+
*
99+
* OPTIONAL
100+
* Default: show all received services
101+
*/
102+
'status.shown_services'=> array(
103+
'serviceIdentifier' => array(
104+
'name' => 'serviceName',
105+
'description' => 'serviceDescription'
106+
),
107+
),
108+
54109
);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"header": {
3+
"en": "Service status",
4+
"cs": "Status služeb"
5+
},
6+
"text": {
7+
"en": "On this page you can find info about the status of different components that are part of the ",
8+
"cs": "Na této stránce naleznete informace o provozu jednotlivých komponent "
9+
},
10+
"aai" : {
11+
"en": "AAI",
12+
"cs": "AAI"
13+
},
14+
"legend": {
15+
"en": "Legend",
16+
"cs": "Legenda"
17+
},
18+
"status_ok": {
19+
"en": "OK",
20+
"cs": "OK"
21+
},
22+
"status_ok_legend": {
23+
"en": "No issues",
24+
"cs": "Služba v pořádku"
25+
},
26+
"status_warning": {
27+
"en": "WARNING",
28+
"cs": "WARNING"
29+
},
30+
"status_warning_legend": {
31+
"en": "Service degradation",
32+
"cs": "Omezený provoz"
33+
},
34+
"status_critical": {
35+
"en": "CRITICAL",
36+
"cs": "CRITICAL"
37+
},
38+
"status_critical_legend": {
39+
"en": "Service outage",
40+
"cs": "Služba mimo provoz"
41+
}
42+
}

lib/NagiosStatusConnector.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/**
4+
* Class sspmod_perun_NagiosStatusConnector
5+
*
6+
* @author Pavel Vyskocil <[email protected]>
7+
*/
8+
class sspmod_perun_NagiosStatusConnector extends sspmod_perun_StatusConnector
9+
{
10+
const NAGIOS_URL = "status.nagios.url";
11+
const NAGIOS_CERT_PATH = "status.nagios.certificate_path";
12+
const NAGIOS_CERT_PASSWORD = "status.nagios.certificate_password";
13+
const NAGIOS_CA_PATH = "status.nagios.ca_path";
14+
const NAGIOS_PEER_VERIFY = "status.nagios.peer_verification";
15+
16+
private $url;
17+
private $certPath;
18+
private $certPassword;
19+
private $caPath;
20+
private $peerVerification;
21+
22+
/**
23+
* NagiosStatusConnector constructor.
24+
*/
25+
public function __construct()
26+
{
27+
parent::__construct();
28+
29+
$this->url = $this->configuration->getString(self::NAGIOS_URL, "");
30+
$this->certPath = $this->configuration->getString(self::NAGIOS_CERT_PATH, "");
31+
$this->certPassword = $this->configuration->getString(self::NAGIOS_CERT_PASSWORD, "");
32+
$this->caPath = $this->configuration->getString(self::NAGIOS_CA_PATH, "");
33+
$this->peerVerification = $this->configuration->getBoolean(self::NAGIOS_PEER_VERIFY, false);
34+
35+
if (empty($this->url)) {
36+
throw new Exception("Required option '" . self::NAGIOS_URL . "' is empty!");
37+
} elseif (empty($this->certPath)) {
38+
throw new Exception("Required option '" . self::NAGIOS_CERT_PATH . "' is empty!");
39+
} elseif (empty($this->caPath)) {
40+
throw new Exception("Required option '" . self::NAGIOS_CA_PATH . "' is empty!");
41+
}
42+
}
43+
44+
45+
public function getStatus()
46+
{
47+
$result = array();
48+
$serviceStatuses = array();
49+
50+
$ch = curl_init();
51+
curl_setopt($ch, CURLOPT_URL, $this->url);
52+
curl_setopt($ch, CURLOPT_VERBOSE, true);
53+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->peerVerification);
54+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
55+
curl_setopt($ch, CURLOPT_SSLCERT, $this->certPath);
56+
curl_setopt($ch, CURLOPT_CAPATH, $this->caPath);
57+
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $this->certPassword);
58+
59+
$response = curl_exec($ch);
60+
61+
if ($response === false) {
62+
\SimpleSAML\Logger::error(curl_error($ch));
63+
}
64+
65+
curl_close($ch);
66+
67+
$jsonResponse = json_decode($response, true);
68+
69+
if (isset($jsonResponse['status']['service_status'])) {
70+
$serviceStatuses = $jsonResponse['status']['service_status'];
71+
}
72+
73+
foreach ($serviceStatuses as $serviceStatus){
74+
$status = array();
75+
$status['name'] = $serviceStatus['service_display_name'];
76+
$status['status'] = $serviceStatus['status'];
77+
array_push($result, $status);
78+
}
79+
80+
return $result;
81+
82+
}
83+
84+
}

lib/StatusConnector.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
4+
/**
5+
* Abstract class sspmod_perun_StatusConnector
6+
* specify interface to get status information about some components
7+
*
8+
* @author Pavel Vyskocil <[email protected]>
9+
*/
10+
abstract class sspmod_perun_StatusConnector
11+
{
12+
13+
const NAGIOS = 'NAGIOS';
14+
15+
const CONFIG_FILE_NAME = "module_perun.php";
16+
const STATUS_TYPE = "status.type";
17+
18+
protected $configuration;
19+
20+
/**
21+
* StatusConnector constructor.
22+
*/
23+
public function __construct()
24+
{
25+
$this->configuration = SimpleSAML_Configuration::getConfig(self::CONFIG_FILE_NAME);
26+
}
27+
28+
/**
29+
* @return sspmod_perun_StatusConnector instance
30+
* @throws SimpleSAML_Error_Exception thrown if interface does not match any supported interface
31+
*/
32+
public static function getInstance() {
33+
$configuration = SimpleSAML_Configuration::getConfig(self::CONFIG_FILE_NAME);
34+
$statusType = $configuration->getString(self::STATUS_TYPE, "NAGIOS");
35+
if ($statusType === self::NAGIOS) {
36+
return new sspmod_perun_NagiosStatusConnector();
37+
} else {
38+
throw new SimpleSAML_Error_Exception("Unknown StatusConnector type in option '" . self::STATUS_TYPE . "'. Only " .
39+
self::NAGIOS . " type available now!");
40+
}
41+
}
42+
43+
/**
44+
* Returns list of components with statuses in this format:
45+
* array(
46+
* array(
47+
* 'name' => 'Component name',
48+
* 'status' => 'Component status'
49+
* ),
50+
* ),
51+
*
52+
* @return array
53+
*/
54+
public abstract function getStatus();
55+
56+
}

templates/status-tpl.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Template of page, which showing status of used components
4+
*
5+
* @author Pavel Vyskocil <[email protected]>
6+
*/
7+
8+
$config = SimpleSAML_Configuration::getInstance();
9+
$instanceName = $config->getString('instance_name', '');
10+
11+
$this->data['header'] = $instanceName . ' ' . $this->t('{perun:status:aai}') . ' ' . $this->t('{perun:status:header}');
12+
$this->data['head'] = '<link rel="stylesheet" media="screen" type="text/css" href="' .
13+
SimpleSAML\Module::getModuleUrl('perun/res/css/status.css') . '" />';
14+
15+
$services = $this->data['services'];
16+
17+
$this->includeAtTemplateBase('includes/header.php');
18+
19+
echo '<p>' . $this->t('{perun:status:text}') . ' ' . $instanceName . ' ' . $this->t('{perun:status:aai}') . '.</p>';
20+
21+
echo '<div class="services">';
22+
23+
foreach ($services as $service) {
24+
echo '<div class="row service">';
25+
echo '<h3>' . $service['name'] . getBadgeByStatus($service['status']) . ' </h3>';
26+
if (isset($service['description']) && !empty($service['description'])) {
27+
echo '<p><span class="glyphicon glyphicon-info-sign"></span> ' . $service['description'] . '</p>';
28+
}
29+
echo '</div>';
30+
}
31+
32+
echo '</div>';
33+
34+
echo '<h4>' . $this->t('{perun:status:legend}') . '</h4>';
35+
echo '<div class="row legend">';
36+
echo '<div class="col-md-4">';
37+
echo '<p><span class="label label-success">' . $this->t('{perun:status:status_ok}') .
38+
'</span> - ' . $this->t('{perun:status:status_ok_legend}') . '</p>';
39+
echo '</div class="col-md-4">';
40+
echo '<div class="col-md-4">';
41+
echo '<p><span class="label label-warning">' . $this->t('{perun:status:status_warning}') .
42+
'</span> - ' . $this->t('{perun:status:status_warning_legend}') . '</p>';
43+
echo '</div class="col-md-4">';
44+
echo '<div class="col-md-4">';
45+
echo '<p><span class="label label-danger">' . $this->t('{perun:status:status_critical}') .
46+
'</span> - ' . $this->t('{perun:status:status_critical_legend}') . '</p>';
47+
echo '</div class="col-md-4">';
48+
echo '</div>';
49+
50+
$this->includeAtTemplateBase('includes/footer.php');

www/res/css/status.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#header h1 {
2+
font-size: 38px;
3+
padding-bottom: 50px;
4+
}
5+
6+
.service {
7+
width: 80%;
8+
margin-left: 0;
9+
}
10+
11+
.service h3, h5{
12+
border-bottom: none;
13+
}
14+
15+
.status {
16+
float: right;
17+
}
18+
19+
.row {
20+
padding-top: 10px;
21+
padding-bottom: 10px;
22+
}
23+
24+
.services {
25+
margin-bottom: 75px;
26+
}
27+
28+
.legend p {
29+
margin: 0 0 0 0;
30+
text-align: center;
31+
}
32+
33+
34+
#footer {
35+
margin-top: -20px;
36+
}

0 commit comments

Comments
 (0)