Greetings experts,
How to set up script to check whether Rest API Server Is Up or Down
Hope all is well.
We are trying to set up a script that checks all the public facing REST servers and indicates if they are currently down or not. The script should check every hour and send out an email if any of them are not accessible. It should also send an email confirming the status for everything 3 times a day at 7:30am, 12:30pm. 3:30pm.
I tried creating a console app to handle these requests but I am stuck with just manually adding a server name to check to but would like to do this for several servers and schedule them as indicated above.
Is this possible?
Here is what I have been able to gobble together.
Your expertise is greatly appreciated.
using System;
using System.Net.NetworkInformation;
namespace showserverstatus
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter server url:");
var url = Console.ReadLine();
Console.Clear();
ServerStatusBy(url);
Console.ReadLine();
}
public static void ServerStatusBy(string url)
{
Ping requestServer = new Ping();
PingReply serverResponse = requestServer.Send(url);
Console.WriteLine("Status of Host: {0}", url);
if (serverResponse.Status == IPStatus.Success)
{
Console.WriteLine("IP Address: {0}", serverResponse.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", serverResponse.RoundtripTime);
Console.WriteLine("Time to live: {0}", serverResponse.Options.Ttl);
Console.WriteLine("Don't fragment: {0}", serverResponse.Options.DontFragment);
Console.WriteLine("Buffer size: {0}", serverResponse.Buffer.Length);
}
else
Console.WriteLine(serverResponse.Status);
}
}
}
Send the emails alerting to an outage to three people including myself.
Send the status 3-times-a-day emails to just myself