summaryrefslogtreecommitdiffstats
path: root/modules-available/dnbd3/hooks/main-warning.inc.php
blob: e38048e1dc076d4b98a94116c4991fa6c7d34512 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

if (Dnbd3::isEnabled()) {
	$res = Database::simpleQuery('SELECT s.fixedip, s.lastseen AS dnbd3lastseen, s.errormsg, m.clientip, m.hostname
			FROM dnbd3_server s
			LEFT JOIN machine m USING (machineuuid)
			WHERE errormsg IS NOT NULL');

	while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
		$error = $row['errormsg'] ? $row['errormsg'] : '<unknown error>';
		$lastSeen = Util::prettyTime($row['dnbd3lastseen']);
		if ($row['fixedip'] === '<self>') {
			Message::addError('dnbd3.main-dnbd3-unreachable', true, $error, $lastSeen);
			continue;
		}
		if (!is_null($row['fixedip'])) {
			$ip = $row['fixedip'];
		} else {
			$ip = $row['clientip'] . '/' . $row['hostname'];
		}
		Message::addWarning('dnbd3.dnbd3-proxy-unreachable', true, $ip, $error, $lastSeen);
	}

	unset($res);
}