Windows File System Redirector with Chef Client/Ruby

I was recently using the windows_zipfile resource to unzip content to the path C:\Windows\System32\WindowsPowerShell\v1.0\Modules as part of a recipe in a Chef cookbook which would complete successfully, but on observation would unzip the contents to C:\Windows\SysWow64\WindowsPowerShell\v1.0\Modules and cause an error when further resources references this source.

The cause of this behaviour is due to the the chef-client and ruby versions are running as 32-bit and the file system redirector redirects access to C:\Windows\SysWow64 instead of C:\Windows\System32.

In order to workaround this issue we can substitute C:\Windows\Sysnative for C:\Windows\System32, by using this alias the file system redirection is bypassed.

In my example, I modified my original resource in the recipie to now include the alias.

windows_zipfile 'C:/Windows/System32/WindowsPowershell/v1.0/Modules/' do 
....
end
windows_zipfile 'C:/Windows/Sysnative/WindowsPowershell/v1.0/Modules/' do
....
end
Advertisements

Enable iOS devices to print to Windows Print Server using AirPrint

I was recently looking into having iOS devices print to Windows Print Server using the AirPrint feature, in order to do so I found a number of articles to install third party tools to achieve this.

Firstly, I needed to install the Bonjour Print Services from http://support.apple.com/kb/DL999 and if required enable inbound connections on UDP service port 5353.

Once this is installed, you will need to install the AirPrint component from http://cdn.tweaks.com/dl/article_mirror/airprint_installer.exe.

Once downloaded run the executable, and select Install AirPrintService and set to the Startup Type to Automatic.

Authentication may be handled by using the domain account of the user, or by granting the guest account access, this will require you to enable the local guest account on the print server.

I had one issue which was fixed by downloading registry entries and following the steps at http://forums.macrumors.com/showthread.php?t=1293865, for iOS devices that are version 5.x and higher.

Checking Free Disk Space on NTFS Volume Mount Points in Nagios

As part of creating external scripts within Nagios I was required to create a script which would monitor NTFS volume mount points which is not available in the default monitoring wizard.

As the script was to be run against a number of different volume mount points, I did not want to create multiple scripts as well as multiple services within Nagios. Therefore, the script defined parameters for the NTFS volume mount points label name, which were called with the MountPoint argument.

Param ([string] $MountPoint)

I had a number of requirements when creating the script. Firstly, the Warning and Critical values as a percentage would be configured to be 80 and 90 respectively. These can be adjusted in the script as below.

$Warning = "80"
$Critical = "90"

Secondly, I had to return the Label, Capacity (GB), Free Space (GB) and Used Space (GB) of the NTFS volume mount point. The NTFS volume mount point was returned using the Get-WmiObject cmdlet and filtering by the Label name.

$Volume = Get-WmiObject Win32_Volume | Where-Object ($_.Label -eq $MountPoint)
$Label = $Volume.Name
$Capacity = $Volume.Capacity /1GB
$FreeSpace = $Volume.FreeSpace / 1GB 
$UsedSpace = ($Volume.Capacity - $Volume.FreeSpace) / 1GB

Finally, we then need to convert the Free Space (GB) and Used Space (GB) into a percentage for generating the status and return an exit code.

$PercentFree = [Math]::Round(($Volume.FreeSpace / $Volume.Capacity) * 100)
$PercentUsed = 100 - [Math]::Round(($Volume.FreeSpace / $Volume.Capacity) * 100)

Now we have the percentage of used space we  can generate the return code to pass to Nagios as a service state by using conditional logic within the script.

If ($PercentUsed -lt $Warning) {$returncode = 0}
ElseIf ($PercentUsed -gt $Warning -and $PercentUsed -lt $Critical) {$returncode = 1} 
ElseIf ($PercentUsed -gt $Critica) {$returncode = 2}

Now all that is left, is to exit the script and return the exit code to Nagios. However, before we do so I want to return Status Information as well to provide the Label, Capacity (GB), Used Space (%) and Free Space (%).

"Disk $Label -total: " + [System.Math]::Round($Capacity, 2) + "GB -used: " + [System.Math]::Round($UsedSpace, 2) + "GB ($PercentUsed%) -free " + [System.Math]::Round($FreeSpace, 2) + "GB ($PercentFree%)"
exit $returncode

Below, is an example of a formatted Status Information message generated:

Disk D:\Disk1\ -total: 200GB -used: 51.16GB (26%) -free 148.84GB (74%)

While the script was created to be executed as an external script within Nagios, this can be run standalone from Windows Powershell. If your are looking to add external scripts to Nagios such as this one see the below link for more information;

https://deangrant.wordpress.com/2013/09/12/creating-and-running-external-scripts-within-nagios-xi/

The full Windows Powershell script can be downloaded from the below link:

https://app.box.com/s/71ouenbu6vvcs6ewe3c7

New paravirtual driver for Amazon EC2 instances

So Amazon have announced a release of a new Amazon Machine Image for Microsoft Windows Server 2003 R2, 2008 and 2008 R2 which now includes a new pararitualized driver, which according to Amazon provides the following benefits:

  • Launch any Microsoft Windows Server AMI (2003 R2 to 2012, 64 bit) on any instance type
  • Increase your Microsoft Windows Server instance storage by mounting up to 25 EBS volumes
  • Improved network reliability and performance

For those who have existing instances and wish to upgrade to the new paravirtualized driver an upgrade script is available from http://aws.amazon.com/developertools/2187524384750206?ref_=pe_173790_28914130_11.

The script will replace the existing paravirtualization driver with an updated driver and will install an updated guest agent service

The script is dependent on the most current version of EC2Config being installed in the existing AMI.

Also, ensure you backup up any data prior to running the upgrade script, or alternatively create an AMI of your existing instance.