Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / agents / plugins / unitrends_backup
blob106038014709bf47b3e47d43515c9647b25b9476
1 #!/usr/bin/php
2 <?php
3 // +------------------------------------------------------------------+
4 // | ____ _ _ __ __ _ __ |
5 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 // | | |___| | | | __/ (__| < | | | | . \ |
8 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 // | |
10 // | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 // +------------------------------------------------------------------+
13 // This file is part of Check_MK.
14 // The official homepage is at http://mathias-kettner.de/check_mk.
16 // check_mk is free software; you can redistribute it and/or modify it
17 // under the terms of the GNU General Public License as published by
18 // the Free Software Foundation in version 2. check_mk is distributed
19 // in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 // out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 // PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 // ails. You should have received a copy of the GNU General Public
23 // License along with GNU Make; see the file COPYING. If not, write
24 // to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 // Boston, MA 02110-1301 USA.
28 print "<<<unitrends_backup:sep(124)>>>\n";
29 $conn = "port=5432 dbname=bpdb user=postgres";
30 $db = pg_connect($conn);
32 $query = "SELECT
33 schedule_id, a.type AS app_type
34 FROM
35 bp.schedules AS s
36 JOIN
37 bp.application_lookup AS a USING(app_id)
38 WHERE
39 enabled=true AND email_report=true
40 ORDER BY s.name";
41 $res = pg_query($db, $query);
43 $start = time() - (24 * 3600);
44 $in = array("start_time" => $start);
45 bp_bypass_cookie(3, 'schedule_report');
47 while ($obj = pg_fetch_object($res)) {
48 if ($obj->app_type == "Archive")
49 continue;
51 $in["schedule_id"] = (int)$obj->schedule_id;
52 $ret = bp_get_schedule_history($in);
53 if (empty($ret[0]["backups"]))
54 continue;
56 print "HEADER|".
57 $ret[0]["schedule_name"]."|" .
58 $ret[0]["application_name"]."|".
59 $ret[0]["schedule_description"]."|".
60 $ret[0]["failures"]."\n";
62 foreach($ret[0]["backups"] as $trash => $backup) {
63 foreach($backup as $row) {
65 $name = $row["primary_name"];
66 switch($ret[0]["app_type"]){
67 case "SQL Server":
68 $name .= "/".$row["secondary_name"];
69 break;
71 case "VMware":
72 $name .= ", VM ".$row["secondary_name"];
73 break;
76 $backup_type = $row["type"];
78 if (!isset($name))
79 $name = $backup_tyoe;
81 $backup_no = (isset($row["backup_id"])) ? $row["backup_id"] : "N/A" ;
83 print "$name|$backup_no|$backup_type|".$row['description']."\n";
87 pg_free_result($res);
88 bp_destroy_cookie();