Skip to content

Instantly share code, notes, and snippets.

@r-plus
Last active August 29, 2015 14:22
Show Gist options
  • Save r-plus/fc224145e466281e604f to your computer and use it in GitHub Desktop.
Save r-plus/fc224145e466281e604f to your computer and use it in GitHub Desktop.
Script to get HVFP filesystem used size via http api.
# Script to get HVFP filesystem used size via http api.
# API Refference: http://itdoc.hitachi.co.jp/Pages/document_list/manuals/vfp.html
$filesystem = "FS01"
# [System.Web.HttpUtility] for japanese UrlEncode if necessary.
#[void]([Reflection.Assembly]::LoadWithPartialName("System.Web"))
# Ignore warning about self signed SSL cert.
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$webReq = [Net.HttpWebRequest]::Create("https://192.168.0.1:9090/mapi/FileSystems/${filesystem}?verbose=true")
$webReq.Method = "GET"
$cookie = New-Object Net.Cookie
$cookie.Name = "api-auth"
# <Base64 username>:<MD5 password>
# default: admin/chang3me!
$cookie.Value = "YWRtaW4=:90406735849e3d510a4d998deb1417e4"
$cc = New-Object Net.CookieContainer
$webReq.CookieContainer = $cc
$domain = New-Object Uri("http://192.168.0.1/")
$webReq.CookieContainer.Add($domain, $cookie)
$webRes = $webReq.GetResponse()
$sr = New-Object IO.StreamReader($webRes.GetResponseStream(), $webRes.ContentEncoding)
$content = [xml]$sr.ReadToEnd()
$sr.Close()
$webRes.Close()
$used = $content.FileSystem.usedBlocksInMegaBytes
$used = $used + " MB"
# test
$used
# Mail
$Subject = "VFP used size."
$Body = $used
$EmailTo = @("to@hogehoge.com", "to2@hogehoge.com")
$EmailFrom = "from@hogehoge.com"
$SMTPServer = "smtp.hogehoge.com"
Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $Subject -Body $Body -SmtpServer $SmtpServer
# .NET version
# Don't line break per mailaddress for Net.Mail.SmtpClient.
$EmailTo = "to@hogehoge.com, to2@hogehoge.com"
$Password = "password"
$SMTPMessage = New-Object Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body);
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25);
# $SMTPClient.EnableSsl = $true;
$SMTPClient.Credentials = New-Object Net.NetworkCredential("username", $Password);
$SMTPClient.Send($SMTPMessage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment