Friday, February 7, 2014

Scripting for Administrators

There is a long standing feud, thanks to Microsoft, between GUI based administrators and command line administrators. Let's face it, a true IT Jedi will want to use scripts and the command line to perform ALL of the tasks for their job. Unfortunately Microsoft thought it would be a good idea for Server operating systems to utilize GUI based tools to perform essential administrative tasks. Albeit this is convenient, it is certainly not ideal when you have to perform the same task on twenty servers, however scripting is. One thing that has irked me about Microsoft is that I've found that there are functions that can not be done in their GUI's, but MUST be done at the command line. So, if you're going to route me to the command line for some things, why not do it for all things? The other issue is that GUI's tend to change look from one version of Windows to the next. Command line options typically never change. So, while it may be a slightly steeper learning curve, the knowledge you learn is less transient than your GUI knowledge. I have started using Powershell for Windows Server and SQL Server administration whenever possible and Perl for Oracle Database administration. (Although, as a database administrator I also have t-sql / pl sql at my disposal as well) So the next time you perform a task, start to think about whether or not you could have scripted or automated the task. Here are the benefits:

  • I have a terrible memory, compartmentalizing tasks to different scripts allows me to forget a lot and still get things done.
  • I like to sleep at night. On the weekends I love to sleep in. With a script you can automatically perform certain actions based on the time or system events. So my minion script will do work for me while I'm snuggled cozily with a blanket.
  • Repetition is boring and will likely give me carpal tunnel syndrome. If I figure out a scripted solution once it may save me from many reiterations of a manual task.
  • You'll begin to think in algorithms more which will allow you to understand how computers function.
  • Once a script is complete you can perform the same tasks on hundreds of systems in a matter of minutes while doing the same task manually may take you days or weeks.
  • An administrator that has some knowledge of task automation is much more valuable to any potential employer.
  • Finding new things to automate brings a new level of excitement and interest to working in IT.

Thursday, January 30, 2014

Check Disk Usage in SQL Server Cluster

We've started using Windows mount points on our Enterprise SQL Server cluster because we've run out of drive letters. Unfortunately, our Orion monitoring software does not support monitoring mount point disk usage without the purchase of an additional license. Rather than go down that path, I scrubbed the internet for a Powershell script that could do the monitoring for me. Unfortunately, I've lost the source - but it wasn't copyrighted so I shouldn't be sued for re-posting the solution.

The script is running locally on one of three servers in the Windows cluster. It queries cluster services to find the host name of each server in the cluster. It then does a check for all disk drives on each host and sends an email if their usage is above a set threshold. This is scheduled to run once a day for me using task scheduler, but you can run it as you like. This script also requires that you are using SQL Server 2008 R2 or higher. There are likely other requirements specific to your environment in order to get this to work, you'll have to work your way through those issues.

###############################################################################
# Check the percentage of free space, including mount points
###############################################################################
# For use in sending alerts via SQL Server Database Mail and may be scheduled
# via a SQL Server Agent job. Create a new Agent job and creat a new step, set
# the Type as PowerShell, edit the code below to put in your server name(s),
# Database Mail profile name, and recipient email address(es), optionally
# change the warning threshold, then paste the code into the Command pane and
# create a schedule.
###############################################################################
# Server names (not SQL Server instance names) must be in single quotes and
# separated by commas. If the SQL Server Agent service account does not have
# admin permissions on remote servers, you must assign Remote Execute
# permissions to the Agent account on each remote server, and the Agent account
# must be a domain account. To assign Remote Execute, run wmimgmt.msc,
# right-click/Properties, select the Security tab, expand the Root node, select
# the CIMV2 node, click the Security button, add the Agent account and scroll
# down to find and check the box for the "Remote Enable" permission.
# 01.17.14 - K. Bumber - I've populated the list of servernames automatically via get-clusternode below.
# Set threshold percentage for low disk capacity warnings.
$Threshold = .1
# Set Email to alert with disk is below threshold
$To = 'dbaemail@domain.com'
# Threshold value must be between 0 and 1.
# (E.g. ".1" will produce warnings when free space is below 10%.
# Set values for units of measure
[string]$UnitOfMeasure = '1GB'
$UnitOfMeasureTerm = "GB"
# Use an empty string for bytes or KB/MB/GB/TB/PB
# (KB-PB are constants in PowerShell)
function sendMail($from, $to, $subject, $body){
     #Write-Host "Sending Email"
     #SMTP server name
     $smtpServer = "smtp.server.com"
     #Creating a Mail object
     $msg = new-object Net.Mail.MailMessage
     #Creating SMTP server object
     $smtp = new-object Net.Mail.SmtpClient($smtpServer)
     #Email structure
     $msg.From = "$from"
     #$msg.ReplyTo = "replyto@xxxx.com"
     $msg.To.Add("$to")
     $msg.subject = "$subject"
     $msg.body = "$body"
     #Sending email
     $smtp.Send($msg)
   }
# List the servers you want to check for low disk capacities
Import-Module FailoverClusters
$ServerCol = get-clusternode
ForEach ($ServerName in $ServerCol)
{
  $Volumes = Get-WmiObject -namespace "root/cimv2" -computername $ServerName.name -query "SELECT Name, Capacity, FreeSpace, DriveType FROM Win32_Volume WHERE DriveType = 3"
 
  ForEach ($Volume in $Volumes)
  {
   
        [string]$DriveType = Switch($Volume.DriveType)
        {
          0{'Unknown'}
          1{'No Root Directory'}
          2{'Removable Disk'}
          3{'Local Disk'}
          4{'Network Drive'}
          5{'Compact Disk'}
          6{'RAM Disk'}
          default {'Unknown'}
        }
       
        #If($DriveType -eq 'Unknown'){BREAK}
        #If $Volume.Name does not start with a capital letter and : then BREAK to the next step in ForEach.
       
        [string]$JustName = "{0}" -f$Volume.Name
        #write-output $JustName
        If("$JustName" -match "^[A-Z]:*")
        {
       
       
            [string]$Drive = "Drive: {0}" -f$Volume.Name          
            [string]$Capacity = "Capacity: {0} {1}" -f[System.Math]::Round(($Volume.Capacity / $UnitOfMeasure),0), $UnitOfMeasureTerm  
            [string]$FreeSpace = "Free Space: {0} {1}" -f[System.Math]::Round(($Volume.FreeSpace / $UnitOfMeasure),0), $UnitOfMeasureTerm
            [string]$PercentFree = "Percent Free Space: " + [System.Math]::Round(($Volume.FreeSpace / $Volume.Capacity), 2)*100 + "%"
            [string]$DriveType = "DriveType: " + $Volume.DriveType
           
            # Send an email alert via Database Mail if a disk is below the warning threshold
           
            If ($Volume.FreeSpace / $Volume.Capacity -lt $Threshold)
            {
              [string]$Subject = "WARNING: Low Disk Space on $ServerName"
              [string]$Body = "WARNING: Low free space on $ServerName `n
                $Drive `n
                $Capacity `n
                $FreeSpace `n
                $PercentFree"
                #edit the line below to figure out where the email came from
              [string]$From = "$ServerName@yourdomain.com"
              sendMail $From $To $Subject $Body
             
            }
           
       
            ###########################################################################
            # If you'd like to get a disk capacity report interactively, comment-out
            # the If statement above and comment-in the following If statement:
            <#
            If ($Volume.FreeSpace / $Volume.Capacity -lt .9)
            {
              Write-Output "WARNING: Disk capacity is less than 90%"
              Write-Output "Server: $ServerName"
              Write-Output $Drive
              Write-Output $Capacity
              Write-Output $FreeSpace
              Write-Output $PercentFree
              Write-Output $DriveType
            }
            Else
            {
              Write-Output "Server: $ServerName"
              Write-Output $Drive
              Write-Output $Capacity
              Write-Output $FreeSpace
              Write-Output $PercentFree
              Write-Output $DriveType
            }
            #>
        }
  }
}




Life as a Database Administrator

Ladies and Gentlemen,

I am proud to announce that I am no longer a Computer Support Specialist. For the past year and a half I've been a full fledged Database Administrator supporting both SQL Server and Oracle Databases. Now, I won't say I'm an expert by any means. RDBMS (relational database management systems) are complex technologies that require copious amounts of proprietary knowledge. So, I'm learning things at my own pace which admittedly is quite slow. I'm a novice dba and I still have plenty more to learn. The ideal thing about being a dba is that I am not limited to just databases. I have the opportunity, and have to, learn a little bit about all of the technologies that go into delivering an application. This allows me to work with the Unix admins, Windows admins, SAN administrators, developers, and business analysts. Basically this means that I am constantly learning something new and am never at a loss for something new.

With that said, I thought my new position would be a great segway to bring myself back into the blogging world. I have aspirations to be a renown author and I would love to publish my own novel. What better way to gain practice for that than to share my opinions, experiences, and solutions to the world on this blog? It will be a chance to flex my literary muscle and embed database solutions into my memory.

So stay tuned ladies and gentlemen, I believe my first post will be about a powershell script that monitors disk usage on a Windows cluster and sends an email when usage is above a specified threshold. Where will the topics wander after that? Only time will tell.

Saturday, June 16, 2012

Ubuntu; why it's amazing and why you should use it

Ubuntu
I love the ideology behind Linux. It seems logical that the best things in life are free. When people come together to donate their time towards creating something to improve humanity rather than make money, magical things can happen. With that said I was always lax to adopt using Linux. Sure it's a great idea on paper, but it never seemed to work quite right for me. My previous attempts have left me in the dark with hardware incompatibility, unavailable drivers, an awkward user experience, and generally just a sour taste in my mouth. I understand that technology can take time to setup and customize, but when I spent over an hour trying to setup a driver that would support Wifi I threw in the towel and went back to Windows. I have to say that Ubuntu 12.04 has changed all of my assumptions about Linux. I find the Unity interface a snap to use. In my opinion it's better than Windows 7's user interface and I consider that to be a good one! I no longer have to worry about Linux not running on my machine. It seems like Canonical and Ubuntu have become mainstream enough to 'just work'. Not to mention the plethora of apps that are available to run on Linux. Here are few that I'm currently using:

  • Chromium web browser - I've become addicted to Google Chrome on Windows and this is the Linux alternative. Chrome is actually a derivative of Chromium.
  • TrueCrypt - this creates an encrypted file container that you can use to encrypt and protect sensitive data. I used this on Windows and was happy to see it available for Linux.
  • Dropbox - how could I go without?! It runs on Linux too.
  • LibreOffice - so far I haven't run into any compatibility problems working with Microsoft Office documents and that was my biggest concern. I'm not too worried about the extra gadgets and gizmo's you get from Microsoft Office. I'm a home productivity suite user at best.
  • FileZilla - free FTP client! Oh and it's on Linux.
  • Skype - yep. Skype.
  • VLC Media Player - This play just about every audio/video format you can think of.
Basically I haven't found anything that I can't do on Linux that I used to do on Windows. I'm primarily using it now because I understand what open source stands for. However, over time I'm sure I'll learn to appreciate the incredibly powerful command line and OS flexibility. Head to the link below to download Ubuntu!

http://www.ubuntu.com/

On the third year he rose again..

It's been about three years since I've posted to this blog. I've decided to take the cheap (free) route and start using Blogger as my writing platform again. After all, it's free and now it plugs right into your Google+! (I just discovered that and am not exactly sure what that implies) To be perfectly honest I am a sucker for any of Google's products. Even though they are starting to become the technology hegemon of our time, I still feel their products have a certain degree of intelligence to them. Certainly more intelligence then I've ever been able to demonstrate. I don't have much to back up my claim and I've admittedly been frustrated with Android's OS fragmentation for some time now, but I'm still a Google fan boy at heart. Competition makes for great results and I'd venture to say that Google introduced plenty of that to our technological world. Do I have a point, other than expressing my feelings for Google, to today's post? Well, no not really. I'm not even sure if this will continue to be a techie blog or if this will migrate towards more of a personal blog. I have a feeling it will be the later. So buckle your seat belts and stay tuned!

Tuesday, April 19, 2011

Antivirus; there can be only one


Please, do NOT install more than one antivirus application computer at a time. If you install more than one antivirus program that actively scans your computer they will be competing with each other for system resources! It's best to only run ONE at a time. I recently cleaned up a PC that had FIVE antivirus programs running at the same time. Can you imagine what happens when all five of those programs try to scan the same file at the same time? The irony behind it all is that even with five antivirus programs running at once they still had malware on the computer!

My guess is that the conflicting antivirus programs slowed the computer down more than the malware..

If you're in need of good free antivirus, my current favorite is Microsoft Security Essentials.

Monday, April 4, 2011

HostsMan

Have a friend that keeps getting malware? Dynamically update his hosts file to prevent infection!

HostsMan is a freeware application that lets you manage your Hosts file with ease. No Spyware! No Adware! No Viruses! 100% Freeware! Clean & simple.