Preston Rodriguez

Sunday, June 26, 2016

Zabbix HipChat Alerts

I've posted a Zabbix HipChat script over on GitHub. It uses the new HipChat cards. This requires using the v2 API so you will need to generate a user API token in order for it to work. The alerts within HipChat look like this.
And when you click on them you can expand them to show more information and relavant links.

The code and instructions are all posted over on my GitHub.
Check it out.

Tuesday, April 26, 2016

IIS FTP HA Cluster

Using Clustering for IIS is not ideal as you should really be using NLB but when you are using IIS on a cluster you cannot have both NLB and clustering setup on the same servers. So Microsoft does offer a way to do this via the generic script option within the cluster manager. Microsoft provides the documentation and script templates for both IIS Websites and FTP Sites. However, the script they provide for FTP simply starts and stop the FTP service and does not allow you to control individual FTP sites. For my needs, I needed to be able to failover different FTP sites that used different IP Bindings. The only scripting language supported by clustering is VBScript and documentation on how to work with IIS with VBScript is little to none. It took me a few hours to piece together the following via trial an error but the following script will allow you to control an individual FTP site. Just create one per site and attach to your cluster roles as needed. You could add more health checks this just simply checks to make sure the site is started within IIS and that the FTP service is running.

Friday, July 31, 2015

Robocopy purge files older than....

I use Robocopy for a lot of things in my workplace. One of the main jobs I use it for is to replicate a file server share from one NAS to a redundant NAS for quick fail-over should the NAS fail. I also like to use that copy for quick restores should someone delete something they shouldn't. The problem with that is if I run a purge on the weekends and someone accidentally deletes something just 6 hours prior to my purge well its gone. So I had to come up with a solution to only purge items older than say 7 days. Originally I thought I could get it all done with PowerShell. I tried using something like the following.
$source = "D:\share"
$destination = "F:\share"
# Directory Compare and Delete if older than 7 Days
Compare-Object (Get-ChildItem $source) (Get-ChildItem $destination)`
| where {$_.SideIndicator -eq "=>"}`
| where {$_.InputObject.LastWriteTime -le (Get-Date).Adddays(-7)}`
| Foreach {Remove-Item -Path $_.InputObject.Fullname}

While that script does actually work it quickly begins to consume large amounts of RAM depending how large your directories are. In my case it ran for about 45 minutes at which point it consumed over 2.5GB of RAM and had my file server at its knees with 98% RAM utilization. Need less to say I had to come up with another solution and this is what I came up with.

This script uses Robocopy to run a purge but with the L switch so it only logs what it would purge without actually performing the task. I then use PowerShell to parse that log file and only pull out the "EXTRA File" and "EXTRA Dir" lines into a parsed log file and clean it up to only have one file path per line.  I then assign the $files variable to all lines that have a "lastwritetime" of 7 days or older. Then perform a for each on the $files variable and delete each file as well as do some console output and logging.