1# BAREOS - Backup Archiving REcovery Open Sourced
2#
3# Copyright (C) 2019-2019 Bareos GmbH & Co. KG
4#
5# This program is Free Software; you can redistribute it and/or
6# modify it under the terms of version three of the GNU Affero General Public
7# License as published by the Free Software Foundation, which is
8# listed in the file LICENSE.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18# 02110-1301, USA.
19#
20# Author: Tobias Plum
21#
22from bareossd import *
23from bareos_sd_consts import *
24
25
26def load_bareos_plugin(context, plugindef):
27    events = []
28    events.append(bsdEventType["bsdEventJobStart"])
29    events.append(bsdEventType["bsdEventDeviceReserve"])
30    events.append(bsdEventType["bsdEventVolumeUnload"])
31    events.append(bsdEventType["bsdEventVolumeLoad"])
32    events.append(bsdEventType["bsdEventDeviceOpen"])
33    events.append(bsdEventType["bsdEventDeviceMount"])
34    events.append(bsdEventType["bsdEventLabelRead"])
35    events.append(bsdEventType["bsdEventLabelVerified"])
36    events.append(bsdEventType["bsdEventLabelWrite"])
37    events.append(bsdEventType["bsdEventSetupRecordTranslation"])
38    events.append(bsdEventType["bsdEventWriteRecordTranslation"])
39    events.append(bsdEventType["bsdEventDeviceUnmount"])
40    events.append(bsdEventType["bsdEventDeviceClose"])
41    events.append(bsdEventType["bsdEventJobEnd"])
42    RegisterEvents(context, events)
43    return bRCs["bRC_OK"]
44
45
46def parse_plugin_definition(context, plugindef):
47    plugin_options = plugindef.split(":")
48    for current_option in plugin_options:
49        key, sep, val = current_option.partition("=")
50        if val == "":
51            continue
52        elif key == "output":
53            global outputfile
54            outputfile = val
55            continue
56        elif key == "instance":
57            continue
58        elif key == "module_path":
59            continue
60        elif key == "module_name":
61            continue
62        else:
63            return bRCs["bRC_Error"]
64        toFile(outputfile)
65
66    return bRCs["bRC_OK"]
67
68
69def handle_plugin_event(context, event):
70    if event == bsdEventType["bsdEventJobStart"]:
71        toFile("bsdEventJobStart\n")
72    elif event == bsdEventType["bsdEventDeviceReserve"]:
73        toFile("bsdEventDeviceReserve\n")
74    elif event == bsdEventType["bsdEventVolumeUnload"]:
75        toFile("bsdEventVolumeUnload\n")
76    elif event == bsdEventType["bsdEventVolumeLoad"]:
77        toFile("bsdEventVolumeLoad\n")
78    elif event == bsdEventType["bsdEventDeviceOpen"]:
79        toFile("bsdEventDeviceOpen\n")
80    elif event == bsdEventType["bsdEventDeviceMount"]:
81        toFile("bsdEventDeviceMount\n")
82    elif event == bsdEventType["bsdEventLabelRead"]:
83        toFile("bsdEventLabelRead\n")
84    elif event == bsdEventType["bsdEventLabelVerified"]:
85        toFile("bsdEventLabelVerified\n")
86    elif event == bsdEventType["bsdEventLabelWrite"]:
87        toFile("bsdEventLabelWrite\n")
88    elif event == bsdEventType["bsdEventSetupRecordTranslation"]:
89        toFile("bsdEventSetupRecordTranslation\n")
90    elif event == bsdEventType["bsdEventWriteRecordTranslation"]:
91        toFile("bsdEventWriteRecordTranslation\n")
92    elif event == bsdEventType["bsdEventDeviceUnmount"]:
93        toFile("bsdEventDeviceUnmount\n")
94    elif event == bsdEventType["bsdEventDeviceClose"]:
95        toFile("bsdEventDeviceClose\n")
96    elif event == bsdEventType["bsdEventJobEnd"]:
97        toFile("bsdEventJobEnd\n")
98
99    return bRCs["bRC_OK"]
100
101
102def toFile(text):
103    doc = open(outputfile, "a")
104    doc.write(text)
105    doc.close()
106