SSIS Package Pings Servers

What is in this article?:

  • SSIS Package Pings Servers
  •  
  •  

Downloads
143994.zip

In many environments, DBAs and SQL Server administrators need to keep a close eye on server connectivity. That's the case where I work. We try to minimize LAN downtime as much as possible so that our extraction, transformation, and loading (ETL) processes run undisturbed.

Related: Troubleshooting Common SQL Server Performance Problems

Although regularly monitoring server connectivity is important, it can be time-consuming. For this reason, I developed a flexible and easy-to-implement SQL Server Integration Services (SSIS) package that uses the Ping command to check the connectivity of each host in my company's IP network. The SSIS package not only finds servers that are unresponsive but also flags servers that aren't responding to pings as often as we'd like, which can help identify potential problems.

The SSIS package executes three stored procedures to ping each host and retrieve the output. I'll show you how to create this package. But first you need to create the stored procedures and the database and tables they use.

Creating the Database, Tables, and Stored Procedures

The first step is to create the database, two tables, and three stored procedures. The database, which is named PingNotification, will hold two tables: ServerList and PingOutput.

The ServerList table will contain a list of the hosts that the SSIS package needs to ping during each run. It has the following columns:

  • ServerName. This column contains the names or IP addresses of the hosts.
  • ServerFileName. If desired, you can use this column to store the pathname of a text file in which you can store the ping results. I won't be using this field for this example.
  • NumberOfPings. This column contains the number of echoes (pings) requested for each host. The default value is 1, but you can specify a different number if desired.
  • ThresholdAvailable. This column contains the threshold value for a host to be considered active. The default value is 100, but you can change that value.

The PingOutput table will store the output from each ping. It has the following columns:

  • ServerName. This column contains the names or IP addresses of the hosts.
  • PingDate. This column stores the date and time of the echo requests.
  • PingAvailability. For each host, this column provides a percentage indicating how many echo requests received replies compared with how many were sent out. When the host isn't found, the value is 0.
  • PingStatus. This column can contain one of three string values. "Normal Response" indicates that the host met or exceeded the value specified in the ThresholdAvailable column of the ServerList table. "Weak or No Response" indicates that the host hasn't replied at all or the number of echoes returned is less than the value specified in the ThresholdAvailable column. "Host Not Found" indicates that the remote server doesn't exist.

I wrote the script PingNotification_CREATE_DATABASE_PROCEDURE.sql to demonstrate how to create the database and tables. This script also populates the tables with sample data in case you want to follow along with the example I'm presenting.

Besides creating the database and tables, the script creates three T-SQL stored procedures:

  • PingListOfServers. This stored procedure executes the Ping command against the servers listed in the ServerName column of the ServerList table. The Ping command's -n switch is used with the value in the NumberOfPings column of the ServerList table to indicate the number of echo requests to send. You can modify this stored procedure by adding other Ping switches. For example, you might want to add the -w switch to set a timeout period.
  • ResultOfPingFailures. This stored procedure determines how many servers didn't exist ("Host Not Found") and how many servers had a lower number of successful echoes than requested ("Weak or No Response"), based on the data in the PingStatus column of the PingOutput table.
  • ResultOfPingForEmail. This stored procedure constructs an email message about any servers that didn't exist, had a weak response, or had no response. Besides the server names, the email message includes the date and time of each ping.

Note that PingListOfServers uses the xp_cmdshell system stored procedure to execute the Ping commands. So, prior to executing PingListOfServers, xp_cmdshell must be enabled on local host. You can enable it by running the command

EXEC sp_configure 'xp_cmdshell', 1;

GO

RECONFIGURE;

GO

When xp_cmdshell is enabled, the PingListOfServers stored procedure uses the Ping command to send echo requests to the servers, as the code in Listing 1 shows. PingListOfServers stores the results in a temporary table, which it creates with an identity column for easier tracking of rows. Figure 1 shows sample Ping command output with the row (i.e., line) numbers added.

Figure 1: Sample Ping Command Output with Line Numbers Added
Figure 1: Sample Ping Command Output with Line Numbers Added 

In the output of each Ping command, the needed result always starts with line 4. When line 4 starts with Reply from, the echo request is successful. When line 4 starts with Request timed out, the echo request failed.

Because the output is set up this way, PingListOfServers uses the code in Listing 2 to capture the information it needs to determine the @ActualAvailability value. This value is important because it's used to determine the values for the PingAvailability and PingStatus columns in the PingOutput table.

 

 »

Discuss this Article 7

ocolamatteo
on Jan 14, 2013
Sorry for the delay. I was not alerted that comments were added to the thread. SSIS offers two options that come to mind immediately, but I am sure there are more. 1. Use the Execute Process Task to call ping and capture the results in a variable using the "StandardOutputVariable" property. 2. SSIS offers full access to .NET via the Script Task. Ping can be accomplished using .NET Ping class and the results captured. Either way it is trivial to get the list of servers from a table in a database, iterate over them and use one of the above two methods to carry out the ping, and finally store the results in a table. No xp_cmdshell required.
ocolamatteo
on Dec 4, 2012
I agree with storing the list of servers in a database table and having a set of procs to retrieve that info and maybe store the outcome of the ping attempts but I strongly object to the use of xp_cmdshell for this task. You can accomplish this task using only the capabilities available within SSIS and avoid enabling xp_cmdshell on the database instance. Keeping the attackable surface area of the database instance to a minimum should always take priority and in this case xp_cmdshell is absolutely unnecessary.
gizzy
on Dec 6, 2012
I created basically the same thing abou 2 years ago. I did not create a SSIS package however (time was not on my side). My is all database driven. I also created a table to store the information of my servers e.g. machine name, IP and type of server. I was monitoring SQL, Intranet, NAS, FTP servers. I can't wait to check out your code to see how you did it. I used a Try/Catch and I was sending pings for server connectivity, a second SP for making a connection into each SQL server and then looping through the database to ping of them, and a third to ping and test for URL responses. I also used DBMail for notifications. Notification to myself and a second Sys Admin is sent if 3 missed pings occur. And then a second email after traking is sent to notify that server/database/URL is back. This is one of those jobs that has been put on the back burner to be updated. So I am anxious to see the methods which you used. Thank you also to the other replies as I will certainly look into your suggestions. At present I am also using xp_cmdshell but at the same time these are all internal servers and I have so many other procedures in place to protect all the servers.
ryanbseattle
on Dec 7, 2012
@ocolamatteo: I agree with BruceH. If you have a better way let's hear it because "You're doing it wrong" isn't a helpful comment. If given the choice, I expect that DBA's who are going to implement a solution like this are going to use a system that they've set up to host tools that they use on a regular basis, or a backend processing server like one used for ETL & EDI. That makes the most sense.
genxeratl
on Jan 7, 2013
Here's my question: while this is impressive that you figured out how to do this with SQL and SSIS why would you ever WANT to? With the plethora of commercial tools out there that can do this for you, obviously for a price, why not purchase one of them? Personally my time is worth more than the purchase price of one of these products - especially over the long term as I add more tasks to my monitoring software. I use Quest's Spotlight and it monitors not only my SQL Servers (and all instances on them) but also my Windows servers (and monitors for all sorts of stuff like connectivity, disk usage and IO, Windows Services, database latency, deadlocks, and so on). It certainly wasn't cheap but is well worth the fact that it was an install, configure, and go method - and I can keep adding things to it plus it give me a really nice GUI that's impressive to Management. And all in one place to boot.
bdheaven@yahoo.com
on Dec 6, 2012
"using only the capabilities available within SSIS" Can you give us an example?
raysot
on May 20, 2013

Why would I want to? Because I have several packages that not only walk through each database on a server,m but they also walk through each server on our network. (SOX-Compliance checkers, Permissions managers, etc...)

Once the package encounters a dead server, it gives up and fails, when in fact I need it to "move on" to the next box.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.