This is my first powershell script I wrote.
I much prefer bash, but with the help of Google I was able to finish this... ;-)
After finding out that one of the servers we're monitoring had a harddisk that wasn't being back-uped I wanted a way to monitor this.
The powershell script is working, but it needs to be run as administrator.
I haven't even tried to run it from Zabbix as I know the first command would fail.
I have this now in zabbix_agentd.conf
It's the last line...
What is needed to run that file using administrator privileges?
Hopefully this can be done with a minimal impact on general security.
Here's the script for those interested:
I much prefer bash, but with the help of Google I was able to finish this... ;-)
After finding out that one of the servers we're monitoring had a harddisk that wasn't being back-uped I wanted a way to monitor this.
The powershell script is working, but it needs to be run as administrator.
I haven't even tried to run it from Zabbix as I know the first command would fail.
I have this now in zabbix_agentd.conf
Code:
UserParameter=reg.info[*],%systemroot%\system32\cscript.exe /nologo /T:10 "C:\Program Files (x86)\Zabbix Agent\reginfo.vbs" "$1" "$2" $3 "$4" UserParameter=net.ping[*], ping -n 1 -w 1 "$1" 2>null | find /i "TTL=" /c UserParameter=vfs.files.exists[*], dir "$1" 2>null | find /c "bytes " UserParameter=vfs.files.countsuffix[*], dir "$2\*.$1" 2>null | find /c /i ".$1" UserParameter=system.notbackuped,powershell -File "C:\Program Files (x86)\Zabbix Agent\NotBackuped.ps1"
What is needed to run that file using administrator privileges?
Hopefully this can be done with a minimal impact on general security.
Here's the script for those interested:
Code:
add-pssnapin windows.serverbackup
# Get Harddisks with a driveletter
$harddisks = GET-WMIOBJECT -query "SELECT * from win32_logicaldisk where Size > 49999999999 and DriveType = 3" | Where-Object {$_.VolumeName -NotMatch 'Back'} | ForEach-Object {$_.DeviceID}
# Extract only the driveletters
# $harddisks = select-string -pattern "DeviceID" WMI_LOGICALDISKS | foreach { $_.ToString().split(" ")[6] }
# Get Windows Backup Policy
Get-WBPolicy >WBPolicy
# Extract the line containing only the backuped items
select-string -pattern "VolumesToBackup" WBPolicy | foreach { $_.ToString().split("{")[1] } >BACKUPED
$notbackuped = ""
# Parse file with driveletters and check if they exist in the current backup-set
foreach ($line in $harddisks)
{
$isbackuped = select-string -pattern $line BACKUPED
if (!$isbackuped) {
$notbackuped = "$notbackuped $line"
}
}
# Write a dot for a system that has all harddisks backuped or the missing harddisks
if ($notbackuped) {
Write-Host $notbackuped
}
else
{
Write-Host "."
}
Comment