1# BAREOS - Backup Archiving REcovery Open Sourced 2# 3# Copyright (C) 2019-2020 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 * 23 24 25def load_bareos_plugin(plugindef): 26 events = [] 27 events.append(bsdEventJobStart) 28 events.append(bsdEventDeviceReserve) 29 events.append(bsdEventVolumeUnload) 30 events.append(bsdEventVolumeLoad) 31 events.append(bsdEventDeviceOpen) 32 events.append(bsdEventDeviceMount) 33 events.append(bsdEventLabelRead) 34 events.append(bsdEventLabelVerified) 35 events.append(bsdEventLabelWrite) 36 events.append(bsdEventSetupRecordTranslation) 37 events.append(bsdEventWriteRecordTranslation) 38 events.append(bsdEventDeviceUnmount) 39 events.append(bsdEventDeviceClose) 40 events.append(bsdEventJobEnd) 41 RegisterEvents(events) 42 return bRC_OK 43 44 45def parse_plugin_definition(plugindef): 46 plugin_options = plugindef.split(":") 47 for current_option in plugin_options: 48 key, sep, val = current_option.partition("=") 49 if val == "": 50 continue 51 elif key == "output": 52 global outputfile 53 outputfile = val 54 continue 55 elif key == "instance": 56 continue 57 elif key == "module_path": 58 continue 59 elif key == "module_name": 60 continue 61 else: 62 return bRC_Error 63 toFile(outputfile) 64 65 return bRC_OK 66 67 68def handle_plugin_event(event): 69 if event == bsdEventJobStart: 70 toFile("bsdEventJobStart\n") 71 elif event == bsdEventDeviceReserve: 72 toFile("bsdEventDeviceReserve\n") 73 elif event == bsdEventVolumeUnload: 74 toFile("bsdEventVolumeUnload\n") 75 elif event == bsdEventVolumeLoad: 76 toFile("bsdEventVolumeLoad\n") 77 elif event == bsdEventDeviceOpen: 78 toFile("bsdEventDeviceOpen\n") 79 elif event == bsdEventDeviceMount: 80 toFile("bsdEventDeviceMount\n") 81 elif event == bsdEventLabelRead: 82 toFile("bsdEventLabelRead\n") 83 elif event == bsdEventLabelVerified: 84 toFile("bsdEventLabelVerified\n") 85 elif event == bsdEventLabelWrite: 86 toFile("bsdEventLabelWrite\n") 87 elif event == bsdEventSetupRecordTranslation: 88 toFile("bsdEventSetupRecordTranslation\n") 89 elif event == bsdEventWriteRecordTranslation: 90 toFile("bsdEventWriteRecordTranslation\n") 91 elif event == bsdEventDeviceUnmount: 92 toFile("bsdEventDeviceUnmount\n") 93 elif event == bsdEventDeviceClose: 94 toFile("bsdEventDeviceClose\n") 95 elif event == bsdEventJobEnd: 96 toFile("bsdEventJobEnd\n") 97 98 return bRC_OK 99 100 101def toFile(text): 102 doc = open(outputfile, "a") 103 doc.write(text) 104 doc.close() 105