Click here to Skip to main content
15,881,766 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex25-Aug-21 8:23
samflex25-Aug-21 8:23 
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
samflex26-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
samflex26-Aug-21 4:04 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex26-Aug-21 5:08
samflex26-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
samflex26-Aug-21 6:41 
Sorry for all the trouble sir.

Please hang in there with me a little longer if you can.

I chose the path of least resistance by publishing and like you correctly stated, it generated .exe file.

I tried testing and ran into an error.

Please see how I was testing and the error:

C:\inetpub\wwwroot\showserverstatus\bin\publish>showserverstatus.exe google.com
IP Address: 2607:f8b0:4000:819::200e
RoundTrip time: 44

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at showserverstatus.Program.ServerStatusBy(String site) in C:\inetpub\wwwroot\showserverstatus\Program.cs:line 41
at showserverstatus.Program.Main(String[] args) in C:\inetpub\wwwroot\showserverstatus\Program.cs:line 16

As you can see, it displayed status of two lines before the error.

This is line 16:
foreach (string site in args)


and this is line 41:
Console.WriteLine("Time to live: {0}", reply.Options.Ttl);


UPDATE:

My demo went well for the mere fact that this app actually ran and sent email was considered a success even though the email did not contain anything.

Here is why.

Due to the error I was getting that I posted above, I removed all of those reply.stuff and then just left only DOWN or WORKING.

They wanted them worded as those.

Per the changes I made below, the app ran and sent the email but when I received the email, there was no message that site is WORKING or DOWN.

Is it because of the changes by replacing Subject with hardcoded values and body with hardcoded values?


They also brought up something that I overlooked.

They wanted Subject to read: Server Status

They wanted the body to read:

Please find the status of the DMZ servers below:


whatever site name is - working or Down (Whatever the status is).
This is latest code.

Please, please forgive me sir for all these troubles. Looks like we are almost there.


I changed the code below to format them just as described above.

The only issue now and it is a big one is that it works with pretty much any URL I tested with except anything that begins with gis.

For instance, none of these worked:

https://gis.massdot.state.ma.us/arcgis/rest
gis.massdot.state.ma.us/arcgis/rest/
gis.massdot.state.ma.us/arcgis/rest

PHP
using System;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Text;
using System.Configuration;
using System.Collections.Generic;

namespace showserverstatus
{
    class Program
    {
        static void Main(string[] args)
        {
            var siteToStatus = new Dictionary<string, string>();
            foreach (var site in args)
            {
                var reply = new Ping().Send(site, 10000);
                siteToStatus[site] = (reply.Status == IPStatus.Success) ? "UP" : "DOWN";
            }
            var subject = "Server Status";
            var body = "Please find the status of the servers below:";
            foreach (var kvp in siteToStatus)
            {
                body += $"{Environment.NewLine}{kvp.Key}: {kvp.Value}";
            }
            SendEmail(subject, body);
        }

        static bool ServerStatusBy(string site)
        {
            Ping pingSender = new();
            PingReply reply = pingSender.Send(site, 10000);
            if (reply.Status != IPStatus.Success)
            {
                SendEmail($"{site} DOWN", $"Ping {site}");
                return false;
            }
            SendEmail($"{site} WORKING", $@"Ping {site}");

            return true;
        }
        public static void SendEmail(string subject, string body)
        {
            using MailMessage mm = new(ConfigurationManager.AppSettings["FromEmail"], "joeblow@yahoo.com");
            mm.To.Add("johndoe@gmail.com");
            mm.CC.Add("joesixpack@yahoo.com");
            mm.Subject = subject;
            mm.Body = body;
            mm.IsBodyHtml = false;

            SmtpClient smtp = new()
            {
                Host = ConfigurationManager.AppSettings["Host"],
                Port = int.Parse(ConfigurationManager.AppSettings["Port"]),
                EnableSsl = true,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]),
            };

            Console.WriteLine("Sending email...");
            smtp.Send(mm);
            Console.WriteLine("Email sent.");
            System.Threading.Thread.Sleep(3000);
        }
    }
}


modified 26-Aug-21 23:19pm.

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
samflex27-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
samflex27-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
Deepak 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 
AnswerRe: Best, cheap, ASP.NET Core hosting? Pin
Moo v This17-Nov-21 2:53
Moo v This17-Nov-21 2:53 
Questionhow to run default page as login page in web app blazor Pin
Member 1129177422-Jul-21 2:54
Member 1129177422-Jul-21 2:54 
Questionncaught ReferenceError:System is not defined at (index):18 dx.light.css:1 Failed to load resource:the server responded with a status of 404(Not Found) Pin
Member 146901009-Jul-21 7:15
Member 146901009-Jul-21 7:15 
AnswerRe: ncaught ReferenceError:System is not defined at (index):18 dx.light.css:1 Failed to load resource:the server responded with a status of 404(Not Found) Pin
SeeSharp29-Jul-21 7:38
SeeSharp29-Jul-21 7:38 
JokeEste site aceita link? Pin
Ronaldo Luis Gonçalves6-Jul-21 3:37
Ronaldo Luis Gonçalves6-Jul-21 3:37 
AnswerRe: Este site aceita link? Pin
SeeSharp29-Jul-21 8:05
SeeSharp29-Jul-21 8:05 
QuestionHow to Upgrade Publish website page in latest version at Visual Studio 2012 Pin
Robymon4-Jul-21 0:39
Robymon4-Jul-21 0:39 

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.