Setting up a Network Monitor with Optitask

As mentioned in the previous post one of the very handy triggers in Optitask can be used to monitor availability of Servers, Routers and other network devices.  To setup a network host monitor here’s what you need to do:

Step 1 – Create a monitor task

I find it easier to organize tasks like these in folders so I create a “Network Monitors” folder and create a new task for each device that I want to monitor.

Step 2 – Execution steps

When a network host is down or becomes available, you may need to receive an Email or SMS notification or you may need to perform more advanced system tasks like shutting down a server, starting an application or whatever. Inside the task you need to define a set of actions to take when the network state is detected. In my case I am monitoring a database server and will send myself an Email when the server goes down.

Step 3 – Setting up the trigger
In the last step I add a new “Network Host Monitor” trigger to the task and specify the server’s IP address. I also select the option to trigger the task when the Host becomes unavailable.

Know It Before Your Users Do

@#it happens. Networks go down, servers crash, Internet connections get slow, disk space disappears and people even sometimes pull the wrong plugs or press the wrong buttons. These are just a handful of the many typical IT problems that we face on a daily basis.

While it’s not always possible to prevent the problems it is possible to be proactive and attend to them before your users start complaining about a print that does not go through or a button that suddenly stopped working.

Optitask has four built-in triggers that could help you monitor for critical system problems and alert you through an Email or SMS message when they occur:

  • Network Host Monitor
  • Program Watcher
  • Event Log Monitor
  • Internet Connection Monitor

Network Host Monitor can be used to trigger an Optitask process when a network host like a router, server, printer or desktop computer becomes unavailable.

Program Watcher can monitor EXE’s and Windows Services that need to run for your software to work.

Event Log Monitor can watch over your System and Application Event Logs and alert you of any specific warnings or errors.

Internet Connection Monitor can detect when your Internet Connection is lost or becomes available.

Scheduling a SQL query or Stored Procedure to execute at specific times

Every so often you run into situations where you need to schedule a stored procedure or SQL query to run at specific times, like a month-end process, batch processing, data archiving etc.

While some database engines like Microsoft SQL support job scheduling others don’t. I found that the problem with native schedulers in databases is that the scheduling itself is often very limited with only support to run the jobs on specific intervals, not specific times or vice versa. Whether your database supports job scheduling or not, let me show you how you can use Optitask to schedule SQL queries or Stored Procedures to execute at specific dates and time intervals.

First you need to create a task, then you need to add a SQL Task action and specify the database connection and the SQL Query to execute. In my example I’ll be executing a stored procedure called “MyStoredProcedureName” and pass the current short date as an input parameter. For long running queries or procedures make sure you set the Command Timeout to an appropriate value in seconds.

After your SQL Task action is setup create a new Scheduling Trigger to specify a schedule to execute the task.

For this task I specified a schedule to start at a specific date and to continue every two weeks on the same day and time.

Another popular feature that cannot always be done with native database schedulers is to handle errors when your Stored Procedure or SQL query fails. With Optitask you can specify “Error Actions” that will execute when your main task fail, in this case I specified an error action to send an Email to our administrator when the SQL task failed:

Kick-Start Optitask Processes Remotely

I am really excited about a new feature for Optitask that I finally released today. The addition is called Optitask Communications Library that allows developers to kick-start Optitask processes from their .NET code locally or remotely over a TCP/IP or HTTP connection.

In more than one occurance I was asked for a solution to start processes remotely. Customers often have a set of stored procedures that takes time to complete that times out when it’s called from their web page or desktop programs. With the new library it’s possible to setup a normal task in Optitask to run the Stored Procedures in managed thread and start the process with the library from a web page.

The Optitask service engine uses the Windows Communication Framework extensively that enabled me with very little code to write a small .NET wrapper around the WCF functions and with two lines of code it’s now possible to  start remote or local Optitask processes.

To use this functionality you would need to download and install the Client Communications Library from our website. Then you need to add a project reference to OT.ClientComm.dll and finally, you need to add the code to start the process:

OT.ClientComm.Connection conn = new OT.ClientComm.Connection
(false, "http://serveraddress/OTService", "DomainName", "UserName", "Password");
 
conn.EnqueueTask("//task[@guid='e50ee464-4f7f-4819-89f4-b39f28a0e45c']");

In the construction of the object you need to pass the address of the server, the protocol (either net.tcp or http) and your Windows Security Credentials if they are used.

The second function takes an XPath parameter to the task that you want to start. You can find the task ID from the Config.xml file in the Optitask directory.