From 14dfaffc809b001115005ac8f6e5333661488fdb Mon Sep 17 00:00:00 2001 From: Marius Pana Date: Mon, 22 Dec 2014 16:59:23 +0200 Subject: [PATCH] initial commit --- agents/plugins/SPH-Exchange-MailboxSize.ps1 | 57 ++++++++++++++++ checkman/exchange_user_mbx_size | 22 ++++++ checks/exchange_user_mbx_size | 67 +++++++++++++++++++ .../check_mk-exchange_user_mbx_size.php | 14 ++++ .../exchange_mbx_size_perfometer.py | 13 ++++ .../exchange_mbx_size_check_parameters.py | 20 ++++++ 6 files changed, 193 insertions(+) create mode 100644 agents/plugins/SPH-Exchange-MailboxSize.ps1 create mode 100644 checkman/exchange_user_mbx_size create mode 100644 checks/exchange_user_mbx_size create mode 100644 pnp-templates/check_mk-exchange_user_mbx_size.php create mode 100644 web/plugins/perfometer/exchange_mbx_size_perfometer.py create mode 100644 web/plugins/wato/exchange_mbx_size_check_parameters.py diff --git a/agents/plugins/SPH-Exchange-MailboxSize.ps1 b/agents/plugins/SPH-Exchange-MailboxSize.ps1 new file mode 100644 index 0000000..cd0d23c --- /dev/null +++ b/agents/plugins/SPH-Exchange-MailboxSize.ps1 @@ -0,0 +1,57 @@ +#[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 +#write-output "" # workaround to prevent the byte order mark to be at the beginning of the first section +##################################################################################### +# Exchange 2010 : per user mailbox size +# Author: Marius Pana +# Company: Spearhead Systems +# Date 12/16/14 +##################################################################################### + +add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 + +# measure time +#Measure-Command {$(Foreach ($mailbox in Get-Recipient -ResultSize Unlimited -RecipientType UserMailbox){ +#$Stat = $mailbox | Get-MailboxStatistics | Select TotalItemSize +# New-Object PSObject -Property @{ +# PrimarySmtpAddress = $mailbox.PrimarySmtpAddress +# TotalItemSize = $Stat.TotalItemSize.value.ToMB() +# } +#}) | Select PrimarySmtpAddress,TotalItemSize | +#Export-CSV C:\CMK-MailboxReport.csv -NTI} + +# filename for timestamp +$remote_host = $env:REMOTE_HOST +$agent_dir = $env:MK_CONFDIR + +$timestamp = $agent_dir + "\timestamp."+ $remote_host + +# execute agent only every $delay seconds - 24 hours +$delay = 86400 + +# does $timestamp exist? +If (Test-Path $timestamp){ + # cat existing outut + write-host "<<>>" + Get-Content C:\CMK-MailboxReport.csv + $filedate = (ls $timestamp).LastWriteTime + $now = Get-Date + $earlier = $now.AddSeconds(-$delay) + # exit if timestamp to young + if ( $filedate -gt $earlier ) { exit } +} +# create new timestamp file +New-Item $timestamp -type file -force | Out-Null + +# calculate unix timestamp +$epoch=[int][double]::Parse($(Get-Date -date (Get-Date).ToUniversalTime()-uformat %s)) + +$(Foreach ($mailbox in Get-Recipient -ResultSize Unlimited -RecipientType UserMailbox){ +$Stat = $mailbox | Get-MailboxStatistics | Select TotalItemSize + New-Object PSObject -Property @{ + PrimarySmtpAddress = $mailbox.PrimarySmtpAddress + TotalItemSize = $Stat.TotalItemSize.value.ToMB() + } +}) | Select PrimarySmtpAddress,TotalItemSize | +Export-CSV C:\CMK-MailboxReport.csv -NoTypeInformation + +(Get-Content C:\CMK-MailboxReport.csv) | Foreach-Object {$_ -replace '"', ''} | Foreach-Object {$_ -replace ',', ' '} | select -Skip 1 | Set-Content C:\CMK-MailboxReport.csv diff --git a/checkman/exchange_user_mbx_size b/checkman/exchange_user_mbx_size new file mode 100644 index 0000000..70c56f3 --- /dev/null +++ b/checkman/exchange_user_mbx_size @@ -0,0 +1,22 @@ +title: Check for users Exchange Mailbox size +agents: windows +catalog: os/windows +license: GPL +distribution: +description: + This check checks for individual exchange mailbox sizes. + You need to install the plugin {SPH-Exchange-MailboxSize.ps1} + into the {plugins} directory of your windows agent. + This check was tested with Exchange 2010 and must have PowerShell + installed. + + The check gets critical if there mailbox is over 2000 MB and warning + if over 1500MB. Both are definable in Wato under "Parameters for + Inventorized Checks", "Applications, Processes & Services". + +inventory: + One service will be created for each user mailbox where the + {SPH-Exchange-MailboxSize.ps1} plugin produces a non-empty output. + +perfdata: + One variable: {size}: the current size of the mailbox in MB. diff --git a/checks/exchange_user_mbx_size b/checks/exchange_user_mbx_size new file mode 100644 index 0000000..4827d46 --- /dev/null +++ b/checks/exchange_user_mbx_size @@ -0,0 +1,67 @@ +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +------------------------------------------------------------------+ +# | ____ _ _ __ __ _ __ | +# | / ___| |__ ___ ___| | __ | \/ | |/ / | +# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | +# | | |___| | | | __/ (__| < | | | | . \ | +# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | +# | | +# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de | +# +------------------------------------------------------------------+ +# +# This file is part of Check_MK. +# The official homepage is at http://mathias-kettner.de/check_mk. +# +# check_mk is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation in version 2. check_mk is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- +# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more de- +# ails. You should have received a copy of the GNU General Public +# License along with GNU Make; see the file COPYING. If not, write +# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301 USA. + +# Author: Marius Pana + +# EXAMPLE DATA FROM: +# fomat: emailaddress size_in_MB +#<<>> +#marius.pana@sphs.ro 177 +#mpana@sphs.ro 81 + +exchange_user_mbx_size_default_values = (1500, 2000) + +def inventory_exchange_user_mbx_size(info): + inventory = [] + for line in info: + useremail = line[0] + mailboxsize = line[1] + inventory.append( (useremail, "exchange_user_mbx_size_default_values") ) + return inventory + + +def check_exchange_user_mbx_size(item, params, info): + #unpack check params + warn, crit = params + for line in info: + if line[0] == item: + mailboxsize = int(line[1]) + perfdata = [ ( "size", mailboxsize, warn, crit ) ] + if mailboxsize > crit: + return (2, "Mailbox size is %dMB" % mailboxsize, perfdata) + elif mailboxsize > warn: + return (1, "Mailbox size is %dMB" % mailboxsize, perfdata) + else: + return (0, "Mailbox size is %dMB" % mailboxsize, perfdata) + return(3, "Mailbox %s not found in agent output" % item) + +check_info["exchange_user_mbx_size"] = { + 'check_function': check_exchange_user_mbx_size, + 'inventory_function': inventory_exchange_user_mbx_size, + 'service_description': '%s Mailbox size', + 'has_perfdata': True, + 'group': 'exchange_user_mbx_size', +} diff --git a/pnp-templates/check_mk-exchange_user_mbx_size.php b/pnp-templates/check_mk-exchange_user_mbx_size.php new file mode 100644 index 0000000..f8868bf --- /dev/null +++ b/pnp-templates/check_mk-exchange_user_mbx_size.php @@ -0,0 +1,14 @@ + diff --git a/web/plugins/perfometer/exchange_mbx_size_perfometer.py b/web/plugins/perfometer/exchange_mbx_size_perfometer.py new file mode 100644 index 0000000..7a00122 --- /dev/null +++ b/web/plugins/perfometer/exchange_mbx_size_perfometer.py @@ -0,0 +1,13 @@ +def perfometer_check_mk_exchange_user_mbx_size(row, check_command, perf_data): + #return 'Hello World! :-)', '' \ + # + perfometer_td(20, '#fff') \ + # + perfometer_td(80, '#ff0000') \ + # + '
' + size = float(perf_data[0][1]) + #return repr(size), '' + color = { 0: "#68f", 1: "#ff2", 2: "#f22", 3: "#fa2" }[row["service_state"]] + #size = perf_data[1] + #print(size) + return "%.0f" % size, perfometer_logarithmic(size, 1024, 2, color) + +perfometers['check_mk-exchange_user_mbx_size'] = perfometer_check_mk_exchange_user_mbx_size diff --git a/web/plugins/wato/exchange_mbx_size_check_parameters.py b/web/plugins/wato/exchange_mbx_size_check_parameters.py new file mode 100644 index 0000000..75056c5 --- /dev/null +++ b/web/plugins/wato/exchange_mbx_size_check_parameters.py @@ -0,0 +1,20 @@ +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# 2014 Marius Pana mp@sphs.ro + + +register_check_parameters( + subgroup_applications, + "exchange_user_mbx_size", + _("MS Exchange User Mailbox Size"), + Tuple( + title = _('Maximum Mailbox Size'), + elements = [ + Integer(title = _("Warning if above"), default_value = 1500 ), + Integer(title = _("Critical if above"), default_value = 2000 ), + ] + ), + None, + None, +) +