Veeam Jobs Plugin with v1 and v2 API

Hi Together,

i needed to work on some stuff and migrated the veeam_jobs Plugin to the new api.

Can someone check if everything is done correctly?
I mean it is working with 2.3.0 but cannot say if the migration is good enough, so the dev Team can use the code to implement it into their checkmk version.

API V1:
/opt/omd/versions/2.3.0b3.cee/lib/python3/cmk/base/plugins/agent_based/veeam_jobs.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from .agent_based_api.v1 import *



def discover_veeam_jobs(section):
    for line in section:
        yield Service(item=line[0])

def check_veeam_jobs(item, section):
    for line in section:
        if len(line) < 6:
            continue  # Skip incomplete lines

        job_name, job_type, job_last_state, job_last_result, job_creation_time, job_end_time = line[
            :6
        ]

        if job_name != item:
            continue  # Skip not matching lines


        if job_last_state in ["Working", "Postprocessing"]:
            state = State.OK
            yield Result(
                state=state,
                summary = f"Running since {job_creation_time} (current state is: {job_last_state})",
            )
            continue


        if job_last_result == "Success":
            state = State.OK
        elif job_last_state == "Idle" and job_type == "BackupSync":
            # A sync job is always idle
            state = State.OK
        elif job_last_result == "Failed":
            state = State.CRIT
        elif job_last_state == "Stopped" and job_last_result == "Warning":
            state = State.WARN
        else:
            state = State.UNKNOWN    
            
        yield Result(
            state=state,
            summary = f"State: {job_last_state}, Result: {job_last_result}, Creation time: {job_creation_time}, End time: {job_end_time}, Type: {job_type}",
        )
        continue



register.check_plugin(
    name = "veeam_jobs",
    service_name = "VEEAM Job %s",
    discovery_function = discover_veeam_jobs,
    check_function = check_veeam_jobs,
)

API V2:
/opt/omd/versions/2.3.0b3.cee/lib/python3/cmk/plugins/veeam/agent_based/veeam.py

#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
# -*- coding: utf-8 -*-
from cmk.agent_based.v2 import (
    CheckPlugin,
    CheckResult,
    DiscoveryResult,
    Service,
    StringTable,
    State,
    Result,
)



def discover_veeam_jobs(section):
    for line in section:
        yield Service(item=line[0])

def check_veeam_jobs(item, section):
    for line in section:
        if len(line) < 6:
            continue  # Skip incomplete lines

        job_name, job_type, job_last_state, job_last_result, job_creation_time, job_end_time = line[
            :6
        ]

        if job_name != item:
            continue  # Skip not matching lines


        if job_last_state in ["Working", "Postprocessing"]:
            state = State.OK
            yield Result(
                state=state,
                summary = f"Running since {job_creation_time} (current state is: {job_last_state})",
            )
            continue


        if job_last_result == "Success":
            state = State.OK
        elif job_last_state == "Idle" and job_type == "BackupSync":
            # A sync job is always idle
            state = State.OK
        elif job_last_result == "Failed":
            state = State.CRIT
        elif job_last_state == "Stopped" and job_last_result == "Warning":
            state = State.WARN
        else:
            state = State.UNKNOWN    
            
        yield Result(
            state=state,
            summary = f"State: {job_last_state}, Result: {job_last_result}, Creation time: {job_creation_time}, End time: {job_end_time}, Type: {job_type}",
        )
        continue

check_plugin_veeam_jobs = CheckPlugin(
    name="veeam_jobs",
    service_name="VEEAM Job %s",
    discovery_function=discover_veeam_jobs,
    check_function=check_veeam_jobs,
)

In booth cases i would advise to create a parse function.
The discover function collides with first lines of the check function if something went wrong in the agent output.
Also some typing would be good for the v2 API.

1 Like

Thank you for the Feedback,
im trying to figure out how the parsing function works exactly.

Maybe i can learn how to do it. If i use the Parse function i always dont get any item back. :smiley:

Best regards,