Module: check_mk
Branch: master
Commit: 6baefcc15a8baf66dc88340f93a1f16c7eef3745
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6baefcc15a8baf…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Thu Jan 23 10:07:02 2014 +0100
Added missing files
---
agents/plugins/unitrends_backup.php | 144 +++++++++++++++++++++++++++++++++++
checkman/unitrends_backup | 17 +++++
checks/unitrends_backup | 76 ++++++++++++++++++
3 files changed, 237 insertions(+)
diff --git a/agents/plugins/unitrends_backup.php b/agents/plugins/unitrends_backup.php
new file mode 100755
index 0000000..47d7d45
--- /dev/null
+++ b/agents/plugins/unitrends_backup.php
@@ -0,0 +1,144 @@
+#!/usr/bin/php
+<?php
+print "<<<unitrends_backup:sep(124)>>>\n";
+$dbconn_string = "port=5432 dbname=bpdb user=postgres";
+$dbconn = pg_connect($dbconn_string);
+if($dbconn === FALSE) {
+ print "ERROR|Cannot connect to database.\n";
+ die(1);
+}
+
+$query = "SELECT schedule_id, a.type AS app_type ";
+$query .= "FROM bp.schedules AS s ";
+$query .= "JOIN bp.application_lookup AS a USING(app_id) ";
+$query .= "WHERE enabled=true AND email_report=true ";
+$query .= "ORDER BY s.name";
+$res = pg_query($dbconn, $query);
+if ($res === false) {
+ print "ERROR|Cannot read schedules table:\n";
+ print pg_last_error($dbconn)."\n";
+ die(1);
+}
+
+$nschedules = 0;
+$nfailed = 0;
+
+$now = time();
+$begin = $now - (24 * 3600);
+$begin = round($begin/3600) * 3600 ;
+$input = array("start_time" => $begin);
+bp_bypass_cookie(3, 'schedule_report');
+
+// Loop through the schedules and get event details from schedule_history
+while ($item = pg_fetch_assoc($res)) {
+ if ($item["app_type"] == "Archive") {
+ continue;
+ }
+ // Get the schedule history
+ $input["schedule_id"] = (int)$item["schedule_id"];
+ $ret = bp_get_schedule_history($input);
+ if ($ret === false) {
+ print "bp_get_schedule_history returned FALSE:\n";
+ print "Error is: ".bp_error()."\n";
+ die(1);
+ }
+ if (empty($ret[0]["backups"])) {
+ continue;
+ }
+
+ $nschedules++;
+ $nfailed += $ret[0]["failures"];
+ $sched = $ret[0];
+
+ // Construct the schedule information section.
+ $aus = "HEADER|".$sched["schedule_name"]."|"
.$sched["application_name"]."|".$sched["schedule_description"]."|".$sched["failures"]."\n";
+ print $aus;
+
+ // The rows correspond to each backup.
+ foreach($sched["backups"] as $event => $bkups) {
+ foreach($bkups as $row) {
+ // Construct the row values for each backup.
+ // Add code here to handle new application-specific name types.
+ $name = $row["primary_name"];
+
+ if ($sched["app_type"] == "SQL Server") {
+ $name .= "/".$row["secondary_name"];
+ }
+ if ($sched["app_type"] == "VMware") {
+ $name .= ", VM ".$row["secondary_name"];
+ }
+
+ // Backup types - these are the strings defined by
+ // bp_get_backup_status
+ switch ($row["type"]) {
+ case "master":
+ $bkup_type = "Master";
+ break;
+ case "exchange full":
+ case "hyperv full":
+ case "mssql full":
+ case "vmware full":
+ case "oracle full":
+ case "sharepoint full":
+ $bkup_type = "Full";
+ break;
+ case "differential":
+ case "exchange differential":
+ case "hyperv differential":
+ case "mssql differential":
+ case "vmware differential":
+ case "sharepoint diff":
+ $bkup_type = "Differential";
+ break;
+ case "exchange incremental":
+ case "hyperv incremental":
+ case "vmware incremental":
+ case "oracle incr":
+ case "incremental":
+ $bkup_type = "Incremental";
+ break;
+ case "mssql transaction":
+ $bkup_type = "Transaction Log";
+ break;
+ case "selective":
+ $bkup_type = "Selective";
+ break;
+ case "baremetal":
+ $bkup_type = "BareMetal";
+ break;
+ default: //just in case
+ $bkup_type = "Unknown";
+ break;
+ }
+
+ if (!isset($name)) {
+ $name = $bkup_type;
+ }
+
+ // Set the Backup Id.
+ if (isset($row["backup_id"])) {
+ $bkup_no = $row["backup_id"];
+ }
+ else {
+ $bkup_no = "N/A";
+ }
+
+
+ $status = $row["description"];
+ $str .= $name."|";
+ $str .= $bkup_no."|";
+ $str .= $bkup_type."|";
+ $str .= $status."\n";
+
+ print $str;
+ }
+ }
+ unset($sched);
+}
+
+pg_free_result($res);
+
+bp_destroy_cookie();
+exit(0);
+
+?>
diff --git a/checkman/unitrends_backup b/checkman/unitrends_backup
new file mode 100644
index 0000000..d8787c7
--- /dev/null
+++ b/checkman/unitrends_backup
@@ -0,0 +1,17 @@
+title: Unitrends Backup Schedule
+agents: linux
+catalog: app/unitrends
+license: GPL
+distribution: check_mk
+description:
+ Unitrends is a enterprise class backup solution.
+ This plugin needs the unitrends_backup plugin installed on the unitrends server
+ in order to work. The plugin will deliver a complete list of all schedules including
+ a sublist of a jobs in this schdule from the last 24 hours.
+
+ As long all of the jobs are succsessful the check returns a {OK} state. In each other
+ case the check will return {CRITICAL}. In anycase it's possible to see the complete
+ log in the long plugin output field from the core.
+
+inventory:
+ One Service for each Schedule will be created
diff --git a/checks/unitrends_backup b/checks/unitrends_backup
new file mode 100644
index 0000000..1a61f53
--- /dev/null
+++ b/checks/unitrends_backup
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+# Header: Schedule Name, Application Name, Schedule Description, Failures
+#<<<unitrends_backup:sep(124)>>>
+#HEADER|DMZ-SR01|Hyper-V 2012|DMZ-HV01|0
+#rodc2|18761|Incremental|Successful
+#rodc2|18761|Incremental|Successful
+#owncloud-test|18762|Incremental|Successful
+
+
+def inventory_unitrends_backup(info):
+ inventory = []
+ for line in info:
+ if line[0] == "HEADER":
+ inventory.append( (line[1], None) )
+ return inventory
+
+def check_unitrends_backup(item, _no_params, info):
+ found = False
+ details = []
+ for line in info:
+ if line[0] == "HEADER" and found:
+ # We are finish collection detail informatoinen
+ break
+
+ if found == True:
+ # Collection Backup deatils
+ app_type, bid, backup_type, status = line
+ details.append("Application Type: %s (%s), %s: %s" % \
+ ( app_type, bid, backup_type, status))
+ continue
+
+ if line[0] == "HEADER" and line[1] == item:
+ found = True
+ head, sched_name, app_name, sched_desc, failures = line
+ message = "%s Errors in last 24/h for Application %s (%s) " % \
+ ( failures, app_name, sched_desc )
+
+ if found == True:
+ message += "\n" + "\n".join(details)
+ if failures == '0':
+ return 0, message
+ else:
+ return 2, message
+ return 3, "Schedule not found in Agent Output"
+
+check_info["unitrends_backup"] = {
+ "check_function" : check_unitrends_backup,
+ "inventory_function" : inventory_unitrends_backup,
+ "service_description" : "Schedule %s",
+}
+