initial commit

This commit is contained in:
Marius Pana 2014-12-22 16:59:23 +02:00
parent 94c231587c
commit 14dfaffc80
6 changed files with 193 additions and 0 deletions

View File

@ -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 "<<<exchange_user_mbx_size>>>"
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

View File

@ -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.

View File

@ -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 <mp@sphs.ro>
# EXAMPLE DATA FROM:
# fomat: emailaddress size_in_MB
#<<<exchange_user_mbx_size>>>
#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',
}

View File

@ -0,0 +1,14 @@
<?php
#
# Copyright (c) 2006-2010 Joerg Linge (http://www.pnp4nagios.org)
# Plugin: check_load
#
$opt[1] = "--vertical-label \"Size in MB\" -X0 -b1024 -l0 --title \"Mailbox Size $servicedesc\" ";
$def[1] = "DEF:var1=$RRDFILE[1]:$DS[1]:MAX ";
if ($WARN[1] != "") {
$def[1] .= "HRULE:$WARN[1]#FFFF00:\"Warning\: $WARN[1]MB\" ";
$def[1] .= "HRULE:$CRIT[1]#FF0000:\"Critical\: $CRIT[1]MB\" ";
}
$def[1] .= rrd::area("var1", "#EACC00", "size ") ;
$def[1] .= rrd::gprint("var1", array("LAST", "AVERAGE", "MAX"), "%6.0lf MB");
?>

View File

@ -0,0 +1,13 @@
def perfometer_check_mk_exchange_user_mbx_size(row, check_command, perf_data):
#return 'Hello World! :-)', '<table><tr>' \
# + perfometer_td(20, '#fff') \
# + perfometer_td(80, '#ff0000') \
# + '</tr></table>'
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

View File

@ -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,
)