Skip to content

Commit

Permalink
Merge pull request #19 from jiuka/check_running_jobs
Browse files Browse the repository at this point in the history
Check running jobs
  • Loading branch information
jiuka authored Jul 3, 2023
2 parents 7df931e + ed342bd commit c480384
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 120 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/symlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ done;
rm -rfv $OMD_ROOT/local/lib/python3/cmk/base/plugins/agent_based
ln -sv $WORKSPACE/agent_based $OMD_ROOT/local/lib/python3/cmk/base/plugins/agent_based

for DIR in 'wato' 'metrics'; do
rm -rfv $OMD_ROOT/local/lib/python3/cmk/gui/plugins/$DIR
ln -sv $WORKSPACE/$DIR $OMD_ROOT/local/lib/python3/cmk/gui/plugins/$DIR
done;

mkdir -p $OMD_ROOT/local/lib/python3/cmk/base/cee/plugins
ln -sv $WORKSPACE/bakery $OMD_ROOT/local/lib/python3/cmk/base/cee/plugins/bakery

Expand Down
108 changes: 83 additions & 25 deletions agent_based/veeam_o365jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# 01234567-89ab-cdef-0123-456789abcdef cmk.onmicrosoft.com Outlook Online Success 29.05.2020 16:45:46 29.05.2020 16:47:55 128.7511818 191 142
# 12345678-9abc-def0-1234-56789abcdef0 cmk.onmicrosoft.com Outlook Online2 Failed 29.05.2020 16:45:46 29.05.2020 16:47:55 128.7511818

from dataclasses import dataclass
from typing import Optional
from .agent_based_api.v1 import (
Service,
Result,
Expand All @@ -29,6 +31,7 @@
render,
register,
)
from .agent_based_api.v1.type_defs import StringTable

VEEAM_O365JOBS_CHECK_DEFAULT_PARAMETERS = {
'states': {
Expand All @@ -40,59 +43,114 @@
}


@dataclass
class VeeamO365Job:
org: str
name: str
state: str
duration: float
objects: Optional[int] = None
transferred: Optional[int] = None
success_age: Optional[int] = None

@property
def name_short(self):
return f"{self.org.replace('.onmicrosoft.com', '')} {self.name}"

@property
def name_full(self):
return f"{self.org} {self.name}"


def parse_veeam_o365jobs(string_table: StringTable) -> dict[str, VeeamO365Job]:
parsed = {}

for item in string_table:
try:
job = VeeamO365Job(
org=item[1],
name=item[2],
state=item[3],
duration=float(item[6]),
)
if len(item) >= 9:
job.objects = int(item[7]) if item[7].isnumeric() else None
job.transferred = int(item[8]) if item[8].isnumeric() else None
if len(item) >= 10:
job.success_age = int(item[9]) if item[9].isnumeric() else None
parsed[item[0]] = job
except Exception:
pass
return parsed


register.agent_section(
name='veeam_o365jobs',
parse_function=parse_veeam_o365jobs,
)


def discovery_veeam_o365jobs(params, section):
appearance = params.get('item_appearance', 'name')

for line in section:
name = line[2]
for id, job in section.items():
name = job.name
if appearance == 'short':
name = '%s %s' % (line[1].replace('.onmicrosoft.com', ''), line[2])
name = job.name_short
elif appearance == 'full':
name = '%s %s' % (line[1], line[2])
yield Service(item=name, parameters={'jobId': line[0]})
name = job.name_full
yield Service(item=name, parameters={'jobId': id})


def check_veeam_o365jobs(item, params, section):
for line in section:
if line[0] != params['jobId']:
continue

job_org, job_name, job_state, \
job_creation_time, job_end_time, job_duration = line[1:7]
job_objects = job_transferred = 0
if len(line) >= 9:
job_objects, job_transferred = line[7:9]
if params.get('jobId', None) not in section:
return
job = section.get(params.get('jobId', None))

if job_state in ['Running']:
yield Result(state=State.OK, summary='Running since %s (current state is: %s)' % (job_creation_time, job_state))
return

state = params.get('states').get(job_state, 3)
yield Result(state=State(state), summary='Status: %s' % job_state)
if job.state == 'Running':
yield from check_levels(
float(job.duration),
levels_upper=params.get('duration', None),
label='Running since',
render_func=render.timespan,
)
else:
state = params.get('states').get(job.state, 3)
yield Result(state=State(state), summary='Status: %s' % job.state)

if int(job_objects):
if job.objects is not None:
yield from check_levels(
int(job_objects),
int(job.objects),
metric_name='items',
label='Transferred Items',
)

if float(job_transferred):
if job.transferred is not None:
yield from check_levels(
float(job_transferred),
float(job.transferred),
metric_name='transferred',
label='Transferred Data',
render_func=render.bytes,
)

yield from check_levels(
float(job_duration),
float(job.duration),
metric_name='duration',
levels_upper=params.get('duration', None),
label='Backup duration',
render_func=render.timespan,
)

if job.success_age is not None:
yield from check_levels(
value=int(job.success_age),
metric_name='age',
levels_upper=params.get('success_maxage', None),
render_func=render.timespan,
label='Last Success',
notice_only=True,
)


register.check_plugin(
name = 'veeam_o365jobs',
Expand Down
15 changes: 13 additions & 2 deletions agents/windows/plugins/veeam_o365_status.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ foreach ($o365Job in $o365Jobs)
$o365JobLastState = $o365Job.LastStatus

$o365JobLastSession = Get-VBOJobSession -Job $o365Job -Last
$o365JobSuccessSession = Get-VBOJobSession -Job $o365Job -Last -Status Success

if ($o365JobLastSession -ne $null) {

$o365JobCreationTime = $o365JobLastSession.CreationTime | get-date -Format "dd.MM.yyyy HH\:mm\:ss" -ErrorAction SilentlyContinue

$o365JobEndTime = $o365JobLastSession.EndTime | get-date -Format "dd.MM.yyyy HH\:mm\:ss" -ErrorAction SilentlyContinue

$o365JobDuration = $($o365JobLastSession.EndTime - $o365JobLastSession.CreationTime).TotalSeconds -as [int]
if ($o365JobLastState -eq 'Running') {
$o365JobDuration = $((Get-Date) - $o365JobLastSession.CreationTime).TotalSeconds -as [int]
} else {
$o365JobDuration = $($o365JobLastSession.EndTime - $o365JobLastSession.CreationTime).TotalSeconds -as [int]
}

$processed = $o365JobLastSession.Statistics.ProcessedObjects -as [int]

Expand All @@ -57,7 +62,13 @@ foreach ($o365Job in $o365Jobs)

}

Write-Host -Separator `t $jobID $jobOrganisation $jobName $o365JobLastState $o365JobCreationTime $o365JobEndTime $o365JobDuration $processed $transferred
if ($o365JobSuccessSession -ne $null) {
$lastSuccessAge = $((Get-Date) - $o365JobSuccessSession.EndTime).TotalSeconds -as [int]
} else {
$lastSuccessAge = $null
}

Write-Host -Separator `t $jobID $jobOrganisation $jobName $o365JobLastState $o365JobCreationTime $o365JobEndTime $o365JobDuration $processed $transferred $lastSuccessAge
}

$o365Licenses = Get-VBOLicense
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from cmk.gui.i18n import _

from cmk.gui.plugins.metrics import (
from cmk.gui.plugins.metrics.utils import (
check_metrics,
metric_info,
graph_info,
Expand All @@ -32,6 +32,7 @@
'transferred': {'name': 'veeam_o365jobs_transferred'},
'duration': {'name': 'veeam_o365jobs_duration'},
'items': {'name': 'veeam_o365jobs_items'},
'age': {'name': 'veeam_o365jobs_age'},
}


Expand All @@ -53,6 +54,12 @@
'color': '#00b336',
}

metric_info['veeam_o365jobs_age'] = {
'title': _('Time since last successfull run'),
'unit': 's',
'color': '#00b336',
}


graph_info['veeam_o365jobs_transferred'] = {
'title': _('Veeam for Office 365 Job'),
Expand All @@ -76,6 +83,12 @@
'range': (0, 'veeam_o365jobs_items:max'),
}

graph_info['veeam_o365jobs_age'] = {
'title': _('Veeam for Office 365 Job'),
'metrics': [('veeam_o365jobs_age', 'area')],
'range': (0, 'veeam_o365jobs_age:max'),
}


perfometer_info.append({
'type': 'stacked',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from cmk.gui.i18n import _

from cmk.gui.plugins.metrics import (
from cmk.gui.plugins.metrics.utils import (
check_metrics,
metric_info,
graph_info,
Expand Down
17 changes: 9 additions & 8 deletions package
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
'windows/plugins/veeam_o365_status.ps1',
],
'checkman': ['veeam_o365jobs', 'veeam_o365licenses'],
'gui': [
'metrics/veeam_o365jobs.py',
'metrics/veeam_o365licenses.py',
'wato/agent_bakery/veeam_o365.py',
'wato/check_parameters/veeam_o365licenses.py',
'wato/check_parameters/veeam_o365jobs.py',
],
'lib': [
'python3/cmk/base/cee/plugins/bakery/veeam_o365.py',
],
'web': [
'plugins/metrics/veeam_o365jobs.py',
'plugins/metrics/veeam_o365licenses.py',
'plugins/wato/agent_bakery_veeam_o365.py',
'plugins/wato/check_parameters_veeam_o365licenses.py',
'plugins/wato/check_parameters_veeam_o365jobs.py',
]},
},
'name': 'veeam_o365',
'title': u'Veeam for Office 365 Checks',
'version': '2.6.0',
'version': '2.6.1',
'version.min_required': '2.2.0',
'version.packaged': '2.2.0',
'version.usable_until': '2.3.0'
Expand Down
Loading

0 comments on commit c480384

Please sign in to comment.