Click here to Skip to main content
15,435,438 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex24-Aug-21 5:08
Membersamflex24-Aug-21 5:08 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
David Mujica24-Aug-21 6:04
MemberDavid Mujica24-Aug-21 6:04 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex24-Aug-21 6:09
Membersamflex24-Aug-21 6:09 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex25-Aug-21 4:18
Membersamflex25-Aug-21 4:18 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
David Mujica25-Aug-21 5:24
MemberDavid Mujica25-Aug-21 5:24 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex25-Aug-21 6:09
Membersamflex25-Aug-21 6:09 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming25-Aug-21 6:18
mveRichard Deeming25-Aug-21 6:18 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex25-Aug-21 8:23
Membersamflex25-Aug-21 8:23 
WOW, thank you very much sir.

You remind me so much of this super guru called Bill Wilkinson of classic ASP and JavaScript way back when I was learning classic ASP.

Just when I felt stuck and in trouble, he would come out of nowhere to help me out.

God bless you sir.

Please forgive me for additional questions.

1, does this ... (the dot dot dot) mean there is more code to go in there?
2, I use this -> YourApp.exe site1.local codeproject.com google.com for scheduling the run times, correct?
3, This -> YourApp.exe site1.local codeproject.com google.com means that I can add the five links all at once correct?

Many thanks again. I really appreciate your help.

I feel a bit better now.


UPDATE: I think I answered question #1.

This is how I *THINK* the code should look like now.

I added the email component since users will be getting emails with the status of the servers whether up or down.

Email subject should indicate Server Up or Down bases on what happens on ServerStatusBy() method

using System;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Text;
using System.Configuration;

namespace showserverstatus
{
    class Program
    {
        private string statusMessage;
        static int Main(string[] args)
        {
           int result = 0;
            foreach (string site in args)
            {
                if (!ServerStatusBy(site))
                {
                    result++;
                }
            }

            return result;

        }

        static bool ServerStatusBy(string site)
        {
            Ping pingSender = new Ping();
            PingReply reply = pingSender.Send(site, 10000);
            if (reply.Status != IPStatus.Success)
            {
                Console.WriteLine("{0}: {1}", site, reply.Status);
                string statusMessage = "Shw message that Server is down"; //Dont know if I am doing this correctly.
                SendEmail(); // Send out email when server is down
                return false;

            }
            else
                statusMessage = "Shw message that Server is up"; //Dont know if I am doing this correctly.
            Console.WriteLine("IP Address: {0}", reply.Address.ToString());
             Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
             Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
             Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
             Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
            SendEmail(); //Send out email when server is up.
            return true;
        }
        public static void SendEmail()
        {
            using (MailMessage mm = new(ConfigurationManager.AppSettings["FromEmail"],"joe.bloew@yahoo.com"))
            {
                mm.To.Add("joesixpack@gmail.com");
                mm.CC.Add("janeDoe@gmail.com");
                mm.Subject = statusMessage; // I would like to show Subject as either Server is down or Up based on what happened in ServerStatusBy() method.
                mm.Body = "Test";
                mm.IsBodyHtml = false;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = ConfigurationManager.AppSettings["Host"];
                smtp.EnableSsl = true;
                NetworkCredential NetworkCred = new NetworkCredential(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]);
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]);
                Console.WriteLine("Sending Email......");
                smtp.Send(mm);
                Console.WriteLine("Email Sent.");
                System.Threading.Thread.Sleep(3000);
                Environment.Exit(0);
            }
        }
    }
}


modified 25-Aug-21 19:11pm.

GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming25-Aug-21 22:12
mveRichard Deeming25-Aug-21 22:12 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex26-Aug-21 3:04
Membersamflex26-Aug-21 3:04 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming26-Aug-21 3:52
mveRichard Deeming26-Aug-21 3:52 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex26-Aug-21 4:04
Membersamflex26-Aug-21 4:04 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex26-Aug-21 5:08
Membersamflex26-Aug-21 5:08 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming26-Aug-21 5:19
mveRichard Deeming26-Aug-21 5:19 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex26-Aug-21 6:41
Membersamflex26-Aug-21 6:41 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming26-Aug-21 21:28
mveRichard Deeming26-Aug-21 21:28 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex27-Aug-21 3:21
Membersamflex27-Aug-21 3:21 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming27-Aug-21 4:10
mveRichard Deeming27-Aug-21 4:10 
General(SOLVED) Re: I am having problem creating a script to monitor Rest/API services. Pin
samflex27-Aug-21 5:27
Membersamflex27-Aug-21 5:27 
QuestionBest, cheap, ASP.NET Core hosting? Pin
Chris Maunder4-Aug-21 8:36
cofounderChris Maunder4-Aug-21 8:36 
AnswerRe: Best, cheap, ASP.NET Core hosting? Pin
jkirkerx11-Aug-21 11:15
professionaljkirkerx11-Aug-21 11:15 
GeneralRe: Best, cheap, ASP.NET Core hosting? Pin
Chris Maunder11-Aug-21 11:56
cofounderChris Maunder11-Aug-21 11:56 
GeneralRe: Best, cheap, ASP.NET Core hosting? Pin
jkirkerx11-Aug-21 12:50
professionaljkirkerx11-Aug-21 12:50 
AnswerRe: Best, cheap, ASP.NET Core hosting? Pin
Deepak Vasudevan13-Sep-21 21:42
MemberDeepak Vasudevan13-Sep-21 21:42 
GeneralRe: Best, cheap, ASP.NET Core hosting? Pin
Chris Maunder14-Sep-21 4:38
cofounderChris Maunder14-Sep-21 4:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.