Example #1
0
    def __init__(self, plugindef):
        bareosdir.DebugMessage(
            100, "Constructor called in module %s\n" % (__name__))
        events = []

        events.append(bDirEventType["bDirEventJobStart"])
        events.append(bDirEventType["bDirEventJobEnd"])
        events.append(bDirEventType["bDirEventJobInit"])
        events.append(bDirEventType["bDirEventJobRun"])
        bareosdir.RegisterEvents(events)

        # get some static Bareos values
        self.jobName = bareosdir.GetValue(brDirVariable["bDirVarJobName"])
        self.jobLevel = chr(bareosdir.GetValue(brDirVariable["bDirVarLevel"]))
        self.jobType = bareosdir.GetValue(brDirVariable["bDirVarType"])
        self.jobId = int(bareosdir.GetValue(brDirVariable["bDirVarJobId"]))
        self.jobClient = bareosdir.GetValue(brDirVariable["bDirVarClient"])
        self.jobStatus = bareosdir.GetValue(brDirVariable["bDirVarJobStatus"])
        self.Priority = bareosdir.GetValue(brDirVariable["bDirVarPriority"])

        bareosdir.DebugMessage(
            100,
            "JobName = %s - level = %s - type = %s - Id = %s - \
Client = %s - jobStatus = %s - Priority = %s - BareosDirPluginBaseclass\n" % (
                self.jobName,
                self.jobLevel,
                self.jobType,
                self.jobId,
                self.jobClient,
                self.jobStatus,
                self.Priority,
            ),
        )
Example #2
0
    def handle_plugin_event(self, event):
        super(BareosDirTest, self).handle_plugin_event(event)
        job_name = repr(bareosdir.GetValue(bareosdir.bDirVarJobName))
        job_id = repr(bareosdir.GetValue(bareosdir.bDirVarJobId))
        microtime = round(time() * 1000)
        msg_f = "%s Job:" + job_name + " JobId: " + job_id + " Time: " + repr(
            microtime) + "\n"

        if event == bareosdir.bDirEventJobStart:
            self.toFile(msg_f % "bDirEventJobStart")

        elif event == bareosdir.bDirEventJobEnd:
            self.toFile(msg_f % "bDirEventJobEnd")

        elif event == bareosdir.bDirEventJobInit:
            self.toFile(msg_f % "bDirEventJobInit")

        elif event == bareosdir.bDirEventJobRun:
            self.toFile(msg_f % "bDirEventJobRun")

        return bareosdir.bRC_OK
Example #3
0
    def handle_plugin_event(self, event):
        """
        This method is called for each of the above registered events
        Overload this method to implement your actions for the events,
        You may first call this method in your derived class to get the
        job attributes read and then only adjust where useful.
        """
        if event == bDirEventType["bDirEventJobInit"]:
            self.jobInitTime = time.time()
            self.jobStatus = chr(
                bareosdir.GetValue(brDirVariable["bDirVarJobStatus"]))
            bareosdir.DebugMessage(
                100,
                "bDirEventJobInit event triggered at Unix time %s\n" %
                (self.jobInitTime),
            )

        elif event == bDirEventType["bDirEventJobStart"]:
            self.jobStartTime = time.time()
            self.jobStatus = chr(
                bareosdir.GetValue(brDirVariable["bDirVarJobStatus"]))
            bareosdir.DebugMessage(
                100,
                "bDirEventJobStart event triggered at Unix time %s\n" %
                (self.jobStartTime),
            )

        elif event == bDirEventType["bDirEventJobRun"]:
            # Now the jobs starts running, after eventually waiting some time,
            # e.g for other jobs to finish
            self.jobRunTime = time.time()
            bareosdir.DebugMessage(
                100,
                "bDirEventJobRun event triggered at Unix time %s\n" %
                (self.jobRunTime),
            )

        elif event == bDirEventType["bDirEventJobEnd"]:
            self.jobEndTime = time.time()
            bareosdir.DebugMessage(
                100,
                "bDirEventJobEnd event triggered at Unix time %s\n" %
                (self.jobEndTime),
            )
            self.jobLevel = chr(
                bareosdir.GetValue(brDirVariable["bDirVarLevel"]))
            self.jobStatus = chr(
                bareosdir.GetValue(brDirVariable["bDirVarJobStatus"]))
            self.jobErrors = int(
                bareosdir.GetValue(brDirVariable["bDirVarJobErrors"]))
            self.jobBytes = int(
                bareosdir.GetValue(brDirVariable["bDirVarJobBytes"]))
            self.jobFiles = int(
                bareosdir.GetValue(brDirVariable["bDirVarJobFiles"]))
            self.jobNumVols = int(
                bareosdir.GetValue(brDirVariable["bDirVarNumVols"]))
            self.jobPool = bareosdir.GetValue(brDirVariable["bDirVarPool"])
            self.jobStorage = bareosdir.GetValue(
                brDirVariable["bDirVarStorage"])
            self.jobMediaType = bareosdir.GetValue(
                brDirVariable["bDirVarMediaType"])

            self.jobTotalTime = self.jobEndTime - self.jobInitTime
            self.jobRunningTime = self.jobEndTime - self.jobRunTime
            self.throughput = 0
            if self.jobRunningTime > 0:
                self.throughput = self.jobBytes / self.jobRunningTime

        return bRCs["bRC_OK"]