ZABBIX Forums  
  #1  
Old 04-05-2012, 21:56
LarryPrime LarryPrime is offline
Junior Member
 
Join Date: May 2012
Posts: 1
Exclamation SMART monitoring for windows powershell script

Assuming you have SMART enabled on your windows disks, here's a powershell script that the Zabbix windows agent can use with template_smartd. While smart isn't a very good predictor of drive failure, it can alert you to heat issues. In this example, you'd call the script c:\drivetemp.ps1


Code:
  #IT'S not my fault if you nuke your corp's domain controller hard disks....

#In a nutshell, this is a powershell v.1 script that calls smartctl.exe, does stuff with the values
#and echoes the data back to Zabbix.

#Define the parameters for Zabbix to call
param($arg1,$arg2)

#YOU MUST EDIT & TEST THIS for YOUR SYSTEM.
#start by executing smartctl.exe -a hda > disk1.txt on your system
#then open disk1.txt and start counting lines. 

#zabbix_agentd.conf line for this in windows:
#UserParameter=system.smartd[*],C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe c:\disktemp.ps1 $1 $2

# below is because I'm too lazy to change the parameter names I stole from here:
# http://www.zabbix.com/wiki/howto/monitor/os/linux/smart 
#/dev/sda = hda in Windows

if ($arg1-eq "/dev/sda") {$arg1 = "hda"}
# WTF powershell comparison operator for equals is actually "-eq", but assignment equals is "=".
# Sorry, I did vbscript for a long time and would prefer to spend my syntax time learning 
# python, because that's what all the cool kids write in these days.
if ($arg1-eq "/dev/sdb") {$arg1 = "hdb"}

#requires smartmontools (windows) at the location of your choice as long as it's right on the next line
  # Execute smartctl and assign the output to a variable
    $smartctl ="c:\smartctl.exe -A " + $arg1
# the numbers between the [] are the lines on smartctl -A output that you want
#each drive is different and windows doesn't have that many command-line tools to get everything you want
#so you're left to edit a script below
$smartdata = (Invoke-Expression  $smartctl)[6..23]
$i = 1
do    {
	# all the below is necessary to replace one line of string manipulation in Linux.
	$length = $smartdata[$i].ToString().length
	$e = $smartdata[$i].ToString().Substring(4,24).Trim() 
	$d = $smartdata[$i].ToString().Substring(87,($length-87)).Trim()
	# Temperature needs cleaning
	if ($e-eq "Temperature_Celsius") {$d = $smartdata[$i].ToString().Substring(87,2) }
	if ($e-eq $arg2) { echo $d }
	$i=$i+1
	#echo $i #useful for figuring out how many attributes you can get when you're debugging.
	}
# while number needs equal the number of your data lines. You may need to change 15 to something else.
while ($i-le 15)
Reply With Quote
  #2  
Old 25-07-2012, 12:34
M3ny4 M3ny4 is offline
Junior Member
 
Join Date: Jul 2012
Posts: 1
Default Missing smart data

Hi!

I wrote a litle powerschell for monitoring smaart data of my pc.
Its work for first time, but than random times have missing data, what u can se on this pic:
http://kepfeltoltes.hu/view/120725/m...toltes.hu_.png

The pc is running but the smaart data missed for a half hour missing.
Sometimes collect the data correctly and for an hour don't collect the data.

And i don't know why

Thanks For help!
Reply With Quote
Reply

Tags
powershell, smartctl, windows

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:33.