Commit da951e4a authored by Hugo Leisink's avatar Hugo Leisink

Release 1.3

parent 2cd97cca
<IfModule rewrite_module>
RewriteEngine On
RewriteBase /
RewriteRule . /public/$1 [QSA]
</IfModule>
monitor (1.3) stable; urgency=low
* Improved dashboard.
* Hourly graph added to day overview page.
* Setup module added.
-- Hugo Leisink <hugo@leisink.net> Thu, 3 Sep 2015 14:15:29 +0200
monitor (1.2) stable; urgency=low
* Banshee framework updated to 5.0.
......
UNDERSTAND HOW TO HIAWATHA MONITOR WORKS
=========================================
Read the information at http://www.hiawatha-webserver.org/howto/monitor to understand what the Hiawatha Monitor is and how it works..
Read the information at https://www.hiawatha-webserver.org/howto/monitor to understand what the Hiawatha Monitor is and how it works.
CONFIGURE YOUR WEBSERVER
......@@ -12,16 +12,15 @@ UrlToolkit {
RequestURI isfile Return
Match ^/(css|images|js)/ Return
Match ^/(favicon.ico|robots.txt)$ Return
Match .*\?(.*) Rewrite /index.php?$1
Match .* Rewrite /index.php
Match [^?]*(\?.*)? Rewrite /index.php$1
}
VirtualHost {
Hostname = monitor.domain.com
WebsiteRoot = /var/www/monitor/public
StartFile = index.php
AccessLogfile = /var/www/monitor/logfiles/access.log
ErrorLogfile = /var/www/monitor/logfiles/error.log
StartFile = index.php
ExecuteCGI = yes
# UseFastCGI = PHP5 # Use if you use PHP as a FastCGI daemon
TimeForCGI = 15
......@@ -35,30 +34,29 @@ The Hiawatha Monitor requires the following PHP modules:
php5-mysql and php5-xsl
Use the following PHP settings:
allow_url_include = Off
cgi.fix_pathinfo = 0 (when using FastCGI PHP), 1 (otherwise)
register_globals = Off
date.timezone = <your timezone>
magic_quotes_gpc = Off
register_globals = Off
CONFIGURE YOUR DATABASE
========================
Change the database settings in 'settings/website.conf' and run the script 'database/setup_database'.
Open the website in your browser and follow the instructions on your screen. In case of an error, add /setup to the URL.
CONFIGURE CRON DAEMON
======================
Use the cron daemon to fetch the information from the webservers and to send the daily reports:
Use the following crontab settings to fetch the information from the webservers and to send the daily reports:
# Crontab
SHELL=/bin/sh
MAILTO=<account name of which you can read e-mail>
*/5 * * * * /path/to/monitor/website/database/fetch_webserver_logs
0 0 * * * /path/to/monitor/website/database/delete_old_logs
59 23 * * * /path/to/monitor/website/database/send_reports
*/5 * * * * /path/to/monitor/website/database/fetch_webserver_logs
0 0 * * * /path/to/monitor/website/database/delete_old_logs
59 23 * * * /path/to/monitor/website/database/send_reports
USING THE HIAWATHA MONITOR
===========================
Login with username 'admin' and password 'monitor' and start adding webservers in the Webserver Administration page. Add "MonitorServer = <IP of monitor server> to the configuration file of your Hiawatha webservers.
Don't forget to change the admin password and to check out the settings in the Settings administration page. When you're done testing, set DEBUG_MODE in settings/website.conf to 'no'.
Don't forget to change the admin password and to check out the settings in the Settings administration page. When you're done testing, set DEBUG_MODE in settings/website.conf to 'no' and remove the setup module from settings/public_pages.conf.
......@@ -18,22 +18,28 @@
"Pages" => array("cms/page", "page.png"),
"Webservers" => array("cms/webserver", "webserver.png")));
if (($this->user->id == 1) && ($this->user->password == "610706e9a48f85476e04d270bd6dc7492cdcd9ad7e91878007dff629ab11f195")) {
$this->output->add_system_warning("Don't forget to change the password of the admin account!");
}
/* Show warnings
*/
if ($this->user->is_admin) {
if (($this->user->id == 1) && ($this->user->password == "610706e9a48f85476e04d270bd6dc7492cdcd9ad7e91878007dff629ab11f195")) {
$this->output->add_system_warning("Don't forget to change the password of the admin account!");
}
if ($this->settings->secret_website_code == "CHANGE_ME_INTO_A_RANDOM_STRING") {
$this->output->add_system_warning("Don't forget to change the secret_website_code setting.");
}
if ($this->settings->secret_website_code == "CHANGE_ME_INTO_A_RANDOM_STRING") {
$this->output->add_system_warning("Don't forget to change the secret_website_code setting.");
}
if (is_true(DEBUG_MODE)) {
$this->output->add_system_warning("Website is running in debug mode. Set DEBUG_MODE in settings/website.conf to 'no'.");
if (is_true(DEBUG_MODE)) {
$this->output->add_system_warning("Website is running in debug mode. Set DEBUG_MODE in settings/website.conf to 'no'.");
}
}
if ($this->page->pathinfo[1] != null) {
$this->output->add_system_warning("The administration module '%s' does not exist.", $this->page->pathinfo[1]);
}
/* Show icons
*/
if (is_false(MULTILINGUAL)) {
unset($menu["Content"]["Languages"]);
}
......
<?php
class dashboard_controller extends controller {
private $alerts = array(
array("Failed logins", "host", "failed_logins"),
array("Exploit attempts", "host", "exploit_attempts"),
array("CGI errors", "cgi", "cgi_errors"),
array("400 Bad request", "server", "result_bad_request"),
array("Client bans", "host", "bans"),
array("404 Not Found", "host", "result_not_found"),
array("500 Internal Error", "host", "result_internal_error"),
array("403 Forbidden", "host", "result_forbidden"));
private function show_alert($index) {
if (valid_input($index, VALIDATE_NUMBERS, VALIDATE_NONEMPTY) == false) {
return;
} else if ($index >= count($this->alerts)) {
return;
}
list($title, $type, $column) = $this->alerts[(int)$index];
$cache = new cache($this->db, "dashboard_".$this->user->username);
if (($list = $cache->$column) === NULL) {
$function = "get_".$type."_statistics";
$list = $this->model->$function($column);
$cache->store($column, $list, ($this->settings->dashboard_page_refresh * 60) - 1);
}
if ($list == false) {
return;
}
$this->output->open_tag("list", array("title" => $title));
foreach ($list as $name => $item) {
$this->output->add_tag("item", $name, array(
"count" => $item["today"],
"change" => $item["change"]));
}
$this->output->close_tag();
}
public function execute() {
if ($this->page->ajax_request) {
if ($this->page->pathinfo[1] == null) {
$this->output->add_tag("max_alert_count", count($this->alerts));
$this->output->add_tag("page_refresh", $this->settings->dashboard_page_refresh);
} else {
$this->show_alert($this->page->pathinfo[1]);
}
return;
}
if (isset($_SESSION["latest_hiawatha_version"]) == false) {
$hiawatha_website = new HTTPS("www.hiawatha-webserver.org");
if (($result = $hiawatha_website->GET("/latest")) !== false) {
......@@ -8,6 +57,13 @@
}
}
if (isset($_SESSION["latest_mbedtls_version"]) == false) {
$mbedtls_website = new HTTPS("tls.mbed.org");
if (($result = $mbedtls_website->GET("/download/latest-stable-version")) !== false) {
$_SESSION["latest_mbedtls_version"] = $result["body"];
}
}
/* Webserver
*/
if (($webservers = $this->model->get_webservers()) === false) {
......@@ -37,10 +93,19 @@
$webserver["active"] = show_boolean($webserver["active"]);
if ($webserver["version"] != "") {
$parts = explode(",", $webserver["version"], 2);
$parts = explode(",", $webserver["version"]);
list(, $version) = explode("v", $parts[0], 2);
$comparison = version_compare($version, $_SESSION["latest_hiawatha_version"], ">=");
$webserver["uptodate"] = show_boolean($comparison);
foreach ($parts as $part) {
if (in_array(substr(ltrim($part), 0, 3), array("TLS", "SSL"))) {
$version = trim(substr($part, 4), " ()");
if (version_compare($version, $_SESSION["latest_mbedtls_version"], "<")) {
$webserver["uptodate"] .= " (mbed TLS out of date)";
}
}
}
}
$this->output->record($webserver, "webserver");
......@@ -52,37 +117,13 @@
/* Alerts
*/
$timestamp = date("Y-m-d 00:00:00");
$alerts = array(
array("Top failed logins", "get_top_failed_logins", 0),
array("Top events", "get_top_events", 0),
array("Top exploit attempts", "get_top_exploit_attempts", 0),
array("Top CGI errors", "get_top_cgi_errors", 0),
array("Top bad requests", "get_top_bad_requests", 0),
array("Top bans", "get_top_bans", 3),
array("Top Not Founds", "get_top_not_founds", 5),
array("Top Internal Errors", "get_top_internal_errors", 1),
array("Top Forbiddens", "get_top_forbiddens", 3));
foreach ($alerts as $alert) {
list($title, $function, $minimum) = $alert;
if (($list = $this->model->$function($timestamp)) === false) {
return;
}
$this->output->add_javascript("jquery/jquery-ui.js");
$this->output->add_javascript("dashboard.js");
$this->output->add_css("jquery/jquery-ui.css");
$this->output->open_tag("list", array("title" => $title));
foreach ($list as $item) {
if ($item["count"] < $minimum) {
break;
}
$this->output->add_tag("item", $item["label"], array("count" => $item["count"]));
}
$this->output->close_tag();
}
$this->output->add_tag("threshold_change", $this->settings->dashboard_threshold_change);
$this->output->add_tag("threshold_value", $this->settings->dashboard_threshold_value);
$this->output->add_tag("page_refresh", $this->settings->dashboard_page_refresh);
}
}
?>
......@@ -18,6 +18,13 @@
$this->output->add_tag("cancel", "Back", array("page" => $this->settings->start_page));
}
$notification_methods = config_array(NOTIFICATION_METHODS);
$this->output->open_tag("notification");
foreach ($notification_methods as $method => $label) {
$this->output->add_tag("method", $method, array("label" => $label));
}
$this->output->close_tag();
/* Action log
*/
if (($actionlog = $this->model->last_account_logs()) !== false) {
......
<?php
class setup_controller extends controller {
public function execute() {
if ($_SERVER["HTTP_SCHEME"] != "https") {
$this->output->add_system_warning("Be aware! Your connection is not secured by SSL/TLS.");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($_POST["submit_button"] == "Create database") {
$this->model->create_database($_POST["username"], $_POST["password"]);
} else if ($_POST["submit_button"] == "Import SQL") {
$this->model->import_sql();
} else if ($_POST["submit_button"] == "Update database") {
$this->model->update_database();
}
}
$step = $this->model->step_to_take();
$this->output->open_tag($step);
switch ($step) {
case "php_extensions":
$missing = $this->model->missing_php_extensions();
foreach ($this->model->missing_php_extensions() as $extension) {
$this->output->add_tag("extension", $extension);
}
break;
case "db_settings":
$this->model->remove_database_errors();
break;
case "create_db":
$this->model->remove_database_errors();
$username = isset($_POST["username"]) ? $_POST["username"] : "root";
$this->output->add_tag("username", $username);
$this->output->run_javascript("document.getElementById('password').focus()");
break;
case "import_sql":
ob_clean();
break;
case "update_db":
ob_clean();
break;
case "done":
ob_clean();
$this->model->ensure_settings();
break;
}
$this->output->close_tag();
}
}
?>
......@@ -19,21 +19,21 @@
/* Server statistics
*/
$query = "delete from server_statistics where timestamp_end<%s";
$query = "delete from server_statistics where date<%s";
if ($db->query($query, $date) == false) {
exit("Error deleting server statistics.\n");
}
/* Host statistics
*/
$query = "delete from host_statistics where timestamp_end<%s";
$query = "delete from host_statistics where date<%s";
if ($db->query($query, $date) == false) {
exit("Error deleting host statistics.\n");
}
/* CGI statistics
*/
$query = "delete from cgi_statistics where timestamp_end<%s";
$query = "delete from cgi_statistics where date<%s";
if ($db->query($query, $date) == false) {
exit("Error deleting CGI statistics.\n");
}
......
This diff is collapsed.
#!/usr/bin/php
<?php
chdir(dirname($argv[0]));
require("../libraries/banshee.php");
function validate_setting($db, $key, $type, $value) {
if ($db->entry("settings", $key, "key") != false) {
return true;
}
$entry = array(
"key" => $key,
"type" => $type,
"value" => $value);
return $db->insert("settings", $entry) !== false;
}
$db = new MySQLi_connection(DB_HOSTNAME, DB_DATABASE, DB_USERNAME, DB_PASSWORD);
if ($db->connected == false) {
exit("Internal error: database not available.\n");
}
validate_setting($db, "hiawatha_cache_enabled", "boolean", "false");
validate_setting($db, "session_timeout", "integer", "3600");
validate_setting($db, "session_persistent", "boolean", "false");
?>
-- MySQL dump 10.13 Distrib 5.5.43, for debian-linux-gnu (x86_64)
-- MySQL dump 10.13 Distrib 5.5.44, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: hiawatha_monitor
-- ------------------------------------------------------
-- Server version 5.5.43-0ubuntu0.14.04.1
-- Server version 5.5.44-0ubuntu0.14.04.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
......@@ -39,8 +39,8 @@ DROP TABLE IF EXISTS `cgi_statistics`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `cgi_statistics` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`timestamp_begin` datetime NOT NULL,
`timestamp_end` datetime NOT NULL,
`date` date NOT NULL,
`hour` tinyint(3) unsigned NOT NULL,
`webserver_id` int(11) unsigned NOT NULL,
`hostname_id` int(11) unsigned NOT NULL,
`time_0_1` int(10) unsigned NOT NULL,
......@@ -51,6 +51,8 @@ CREATE TABLE `cgi_statistics` (
PRIMARY KEY (`id`),
KEY `webserver_id` (`webserver_id`),
KEY `hostname_id` (`hostname_id`),
KEY `date` (`date`),
KEY `hour` (`hour`),
CONSTRAINT `cgi_statistics_ibfk_1` FOREIGN KEY (`webserver_id`) REFERENCES `webservers` (`id`),
CONSTRAINT `cgi_statistics_ibfk_2` FOREIGN KEY (`hostname_id`) REFERENCES `hostnames` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
......@@ -83,8 +85,8 @@ DROP TABLE IF EXISTS `host_statistics`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `host_statistics` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`timestamp_begin` datetime NOT NULL,
`timestamp_end` datetime NOT NULL,
`date` date NOT NULL,
`hour` tinyint(3) unsigned NOT NULL,
`webserver_id` int(10) unsigned NOT NULL,
`hostname_id` int(10) unsigned NOT NULL,
`requests` int(11) unsigned NOT NULL,
......@@ -98,6 +100,8 @@ CREATE TABLE `host_statistics` (
PRIMARY KEY (`id`),
KEY `webserver_id` (`webserver_id`),
KEY `hostname_id` (`hostname_id`),
KEY `date` (`date`),
KEY `hour` (`hour`),
CONSTRAINT `host_statistics_ibfk_1` FOREIGN KEY (`webserver_id`) REFERENCES `webservers` (`id`),
CONSTRAINT `host_statistics_ibfk_2` FOREIGN KEY (`hostname_id`) REFERENCES `hostnames` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
......@@ -141,7 +145,7 @@ CREATE TABLE `menu` (
LOCK TABLES `menu` WRITE;
/*!40000 ALTER TABLE `menu` DISABLE KEYS */;
INSERT INTO `menu` VALUES (1,0,0,'Dashboard','/dashboard'),(2,0,0,'Request statistics','/request_statistics'),(3,0,0,'Security statistics','/security_statistics'),(4,0,0,'CGI statistics','/cgi_statistics'),(5,0,0,'Server statistics','/server_statistics'),(6,0,0,'Events','/events'),(7,0,0,'Logout','/logout');
INSERT INTO `menu` VALUES (1,0,0,'Dashboard','/'),(2,0,0,'Request statistics','/request_statistics'),(3,0,0,'Security statistics','/security_statistics'),(4,0,0,'CGI statistics','/cgi_statistics'),(5,0,0,'Server statistics','/server_statistics'),(6,0,0,'Events','/events'),(7,0,0,'Logout','/logout');
/*!40000 ALTER TABLE `menu` ENABLE KEYS */;
UNLOCK TABLES;
......@@ -236,7 +240,6 @@ CREATE TABLE `roles` (
`cms/file` tinyint(4) DEFAULT '0',
`cms/language` tinyint(4) DEFAULT '0',
`cms/menu` tinyint(4) DEFAULT '0',
`cms/organisation` tinyint(4) DEFAULT '0',
`cms/page` tinyint(4) DEFAULT '0',
`cms/role` tinyint(4) DEFAULT '0',
`cms/settings` tinyint(4) DEFAULT '0',
......@@ -255,7 +258,7 @@ CREATE TABLE `roles` (
LOCK TABLES `roles` WRITE;
/*!40000 ALTER TABLE `roles` DISABLE KEYS */;
INSERT INTO `roles` VALUES (1,'Administrator',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),(2,'Webmaster',1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0);
INSERT INTO `roles` VALUES (1,'Administrator',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),(2,'Webmaster',1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,0);
/*!40000 ALTER TABLE `roles` ENABLE KEYS */;
UNLOCK TABLES;
......@@ -268,13 +271,15 @@ DROP TABLE IF EXISTS `server_statistics`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `server_statistics` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`timestamp_begin` datetime NOT NULL,
`timestamp_end` datetime NOT NULL,
`date` date NOT NULL,
`hour` tinyint(3) unsigned NOT NULL,
`webserver_id` int(10) unsigned NOT NULL,
`connections` int(10) unsigned NOT NULL,
`result_bad_request` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `webserver_id` (`webserver_id`),
KEY `date` (`date`),
KEY `hour` (`hour`),
CONSTRAINT `server_statistics_ibfk_1` FOREIGN KEY (`webserver_id`) REFERENCES `webservers` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
......@@ -321,7 +326,7 @@ CREATE TABLE `settings` (
LOCK TABLES `settings` WRITE;
/*!40000 ALTER TABLE `settings` DISABLE KEYS */;
INSERT INTO `settings` VALUES (1,'admin_page_size','integer','25'),(2,'page_after_login','string','dashboard'),(3,'start_page','string','dashboard'),(4,'webmaster_email','string','root@localhost'),(5,'head_title','string','Hiawatha Monitor'),(6,'head_description','string','Security and performance monitoring tool for the Hiawatha webserver.'),(7,'head_keywords','string','monitor, hiawatha'),(34,'default_language','string','en'),(42,'session_persistent','boolean','false'),(38,'event_page_size','integer','25'),(39,'top_connections','integer','15'),(43,'session_timeout','integer','1200'),(44,'hiawatha_cache_enabled','boolean','false'),(45,'secret_website_code','string','CHANGE_ME_INTO_A_RANDOM_STRING'),(46,'hiawatha_cache_default_time','integer','3600');
INSERT INTO `settings` VALUES (1,'admin_page_size','integer','25'),(2,'page_after_login','string','dashboard'),(3,'start_page','string','dashboard'),(4,'webmaster_email','string','root@localhost'),(5,'head_title','string','Hiawatha Monitor'),(6,'head_description','string','Security and performance monitoring tool for the Hiawatha webserver.'),(7,'head_keywords','string','monitor, hiawatha'),(34,'default_language','string','en'),(42,'session_persistent','boolean','true'),(38,'event_page_size','integer','25'),(39,'top_connections','integer','15'),(46,'hiawatha_cache_default_time','integer','3600'),(43,'session_timeout','integer','38400'),(44,'hiawatha_cache_enabled','boolean','false'),(45,'secret_website_code','string','CHANGE_ME_INTO_A_RANDOM_STRING'),(55,'dashboard_page_refresh','integer','1'),(48,'report_history_days','integer','15'),(49,'report_alert_medium','integer','150'),(50,'report_alert_high','float','3'),(51,'report_use_median','boolean','true'),(52,'report_skip_normal','boolean','true'),(53,'dashboard_threshold_change','integer','150'),(54,'dashboard_threshold_value','integer','10'),(56,'database_version','integer','103');
/*!40000 ALTER TABLE `settings` ENABLE KEYS */;
UNLOCK TABLES;
......@@ -385,7 +390,7 @@ CREATE TABLE `users` (
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,1,'admin','610706e9a48f85476e04d270bd6dc7492cdcd9ad7e91878007dff629ab11f195',NULL,0,1,'Administrator','root@localhost','','none',0);
INSERT INTO `users` VALUES (1,1,'admin','610706e9a48f85476e04d270bd6dc7492cdcd9ad7e91878007dff629ab11f195',NULL,NULL,1,'Administrator','root@localhost','','none',0);
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
......@@ -436,4 +441,4 @@ CREATE TABLE `webservers` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2015-06-14 17:23:58
-- Dump completed on 2015-09-03 12:53:26
#!/usr/bin/php
<?php
define("HISTORY_DAYS", 15);
define("ALERT_MEDIUM", 150);
define("ALERT_HIGH", 300);
define("USE_MEDIAN", true);
define("SKIP_NORMAL", false);
chdir(dirname($argv[0]));
require("../libraries/banshee.php");
require("../libraries/security.php");
require("../libraries/settings.php");
/* Dummy user class
*/
......@@ -40,19 +35,6 @@
}
}
/* Main program
*/
error_reporting(E_ALL & ~E_NOTICE);
/* Connect to database
*/
$db = new MySQLi_connection(DB_HOSTNAME, DB_DATABASE, DB_USERNAME, DB_PASSWORD);
if ($db->connected == false) {
exit("Internal error: database not available.\n");
}
$settings = new settings($db);
/* Calculate median
*/
function get_median($data, $key) {
......@@ -61,7 +43,6 @@
foreach ($data as $item) {
array_push($values, $item[$key]);
}
sort($values);
$count = count($values);
......@@ -76,17 +57,29 @@
return $median;
}
/* Main program
*/
error_reporting(E_ALL & ~E_NOTICE);
/* Connect to database
*/
$db = new MySQLi_connection(DB_HOSTNAME, DB_DATABASE, DB_USERNAME, DB_PASSWORD);
if ($db->connected == false) {
exit("Internal error: database not available.\n");
}
$settings = new settings($db);
/* Get information about webserver
*/
function get_information($db, $table, $columns, $user_id, $webserver_id, $hostnames) {
function get_information($db, $settings, $table, $columns, $user_id, $webserver_id, $hostnames) {
$user = new dummy_user($user_id);
$model = new stats_model($db, $user, $table, $columns, $hostnames);
$begin = date("Y-m-d", strtotime("-".($settings->report_history_days - 1)." days"));
$today = date("Y-m-d");
$begin = date("Y-m-d", strtotime("-".(HISTORY_DAYS - 1)." days"));
$end = date("Y-m-d", strtotime("tomorrow"));
if (($stats = $model->get_statistics($begin, $end, 0, $webserver_id)) === false) {
if (($stats = $model->get_statistics($begin, $today, 0, $webserver_id)) === false) {
return false;
}
......@@ -103,26 +96,26 @@
}
foreach ($result as $idx => $stat) {
if (USE_MEDIAN) {
if ($settings->report_use_median) {
$result[$idx]["previous"] = get_median($stats, $idx);
} else {
$result[$idx]["previous"] = round($stat["previous"] / (HISTORY_DAYS - 1));
$result[$idx]["previous"] = round($stat["previous"] / ($settings->report_history_days - 1));
}
if ($result[$idx]["previous"] != 0) {
$percentage = round($stat["today"] / $result[$idx]["previous"] * 100) - 100;
$result[$idx]["percentage"] = $percentage." %";
$change = round($stat["today"] / $result[$idx]["previous"] * 100) - 100;
$result[$idx]["change"] = $change." %";
} else if ($result["today"] == 0) {
$percentage = $stat["today"] * 100;
$result[$idx]["percentage"] = $percentage." %";
$change = $stat["today"] * 100;
$result[$idx]["change"] = $change." %";
} else {
$percentage = 0;
$result[$idx]["percentage"] = "&#8734;";
$change = 0;
$result[$idx]["change"] = "&#8734;";
}
if ($percentage >= ALERT_HIGH) {
if ($change >= $settings->report_alert_high) {
$result[$idx]["alert"] = "high";
} else if ($percentage >= ALERT_MEDIUM) {
} else if ($change >= $settings->report_alert_medium) {
$result[$idx]["alert"] = "medium";
} else {
$result[$idx]["alert"] = "none";
......@@ -134,7 +127,7 @@
/* Generate report for webserver
*/
function generate_report($db, $user, $webserver) {
function generate_report($db, $settings, $user, $webserver) {
static $reports = array();
if (isset($reports[$webserver["id"]])) {
......@@ -177,7 +170,9 @@
$report = array(
"content" => "<h2>".$webserver["name"]."</h2>\n",
"alerts" => array());
$type = USE_MEDIAN ? "Median" : "Average";
$type = $settings->report_use_median ? "Median" : "Average";
$add_count = 0;
foreach ($stats as $label => $stat) {
$header = "<h3>".$label."</h3>\n".
"<table class=\"stats\">\n".
......@@ -185,17 +180,19 @@
$header_set = false;
$columns = array_keys($stat["details"]);
if (($information = get_information($db, $stat["table"], $columns, $user["id"], $webserver["id"], $stat["hostnames"])) == false) {
if (($information = get_information($db, $settings, $stat["table"], $columns, $user["id"], $webserver["id"], $stat["hostnames"])) == false) {
continue;
}
foreach ($information as $column => $value) {
if ($value["percentage"] < ALERT_MEDIUM) {
if (SKIP_NORMAL) {
if ($value["change"] < $settings->report_alert_medium) {
if ($settings->report_skip_normal) {
continue;
}
}
$add_count++;
if ($header_set == false) {
$report["content"] .= $header;
$header_set = true;
......@@ -205,13 +202,15 @@
$previous = graph_model::readable_number($value["previous"]);
$report["content"] .= "<tr><td>".$stat["details"][$column].":</td>".
"<td class=\"alert_".$value["alert"]."\">".$today."</td>".
"<td>".$value["percentage"]."</td><td>".$previous."</td></tr>\n";
"<td>".$value["change"]."</td><td>".$previous."</td></tr>\n";
if ($value["alert"] != "none") {
array_push($report["alerts"], $webserver["name"]);
}
}
$report["content"] .= "</table>\n";
if ($header_set) {
$report["content"] .= "</table>\n";
}
}
$query = "select event, UNIX_TIMESTAMP(timestamp) as timestamp from events ".
......@@ -226,6 +225,12 @@
}
$report["content"] .= "</table>\n";
$add_count++;
}
if ($add_count == 0) {
$report["content"] .= "<p>Nothing to report.</p>\n";
}
$reports[$webserver["id"]] = $report;
......@@ -268,7 +273,7 @@
$report_content = "";
$report_alerts = array();
foreach ($webservers as $webserver) {
if (($report = generate_report($db, $user, $webserver)) == false) {
if (($report = generate_report($db, $settings, $user, $webserver)) == false) {
continue;
}
$report_content .= $report["content"];
......@@ -290,7 +295,8 @@
$replace = array(
"ALERTS" => $report_alerts,
"CONTENT" => $report_content,
"HISTORY" => HISTORY_DAYS - 1,
"TYPE" => $settings->report_use_median ? "median" : "average",
"HISTORY" => $settings->report_history_days - 1,
"TIMESTAMP" => date("j F Y, H:i (O)"));
$email = new email("Daily Hiawatha Monitor report", $settings->webmaster_email);
......