This topic is resolved

Share

This topic contains 11 replies, has 3 voices, and was last updated by  PNN 1 month, 1 week ago.

  • Author
    Posts
  • #337499
     PNN 
    Participant
    • Topics: 1
    • Replies: 6
    Post count: 18
    Member Points: 184
    Rank: Level 1

    Dear IT pros

    I am trying to write a script that will check the ping status of various servers and check if ping is unsuccessful, restart the network service/adapter and send a notification to via email. Any help will be appreciated. Thanks

    2+
  • #337894
     Michael Pietroforte 
    Keymaster
    • Topics: 142
    • Replies: 345
    Post count: 1090
    Member Points: 8,044
    Rank: Level 1

    How about this:

    2+
    • #345245
       PNN 
      Participant
      • Topics: 1
      • Replies: 6
      Post count: 18
      Member Points: 184
      Rank: Level 1

      Thanks Michael. Sorry I couldn’t reply sooner. Proceeded on leave from work and got caught up doing other stuff. I have tested the script on powershell but whether a server is down or up, am getting ‘server replied’ thus not really working. Also, the server replied message keeps running continuously until you break the script. It should just give one response if up and if down reset the network adapter if ping results are ‘timeouts’ and not ‘destination server unreachable’ since if the server is unreachable it means it is powered off.

      2+
      • #345264
         Michael Pietroforte 
        Keymaster
        • Topics: 142
        • Replies: 345
        Post count: 1090
        Member Points: 8,044
        Rank: Level 1

        I have tested the script and it works. You can try it by disconnecting the machine where the script runs  from the network.

        Of course, you need an infinite loop if you want to test the availability of a server. The server is running all day, right?

        And the script does give you a response if the server has an internet connection. If the connection is lost, it leaves the loop, gives you a corresponding notice, restarts the network adapter and then sends an email to the admin.

        However, from your last message, it is unclear what you are trying to accomplish. Do you want to test a remote server or the server where the script runs? If your problem is that a remote server is down because the network adapter is malfunctioning, you obviously can’t fix that problem remotely. How can you reach the server if it is no longer connected?

        So the little script I wrote has to run on the server with the network adapter problem. It can ping any machine in your network and once the ping fails, it will restart the local network adapter.

        2+
        • #346720
           PNN 
          Participant
          • Topics: 1
          • Replies: 6
          Post count: 18
          Member Points: 184
          Rank: Level 1

          Thanks, Michael. I think I did not explain clearly what I am trying to accomplish but your solution solves part of my problem. I can run this script on each of my servers. I was thinking of running the script from a central server that can reach all the others say domain controller and reset adapters of these servers (in a CSV list) in case of timeouts only and then send a notification.
          Our servers are connected to the local domain and from time to time, they lose identity and show unidentified network or public network instead of domain network affecting applications that require domain authentication. We normally just reset the adapter, or enable/disable it or restart network services/network location awareness service to revert it back to the domain network. All these servers also have access to the internet. Also to note is that most of the servers are VMs running on VMWare.

          What I want to accomplish is to automate this process of resetting the adapter/restarting network services when the server loses domain identity since it happens so randomly. Then the email notification is to inform me of the action. We use office365 as our exchange server so the email notification can only happen if there is a successful internet connection.  It is a bit frustrating to get the operations team inform you of a downtime and you were not aware.

          I hope my explanation is clearer now. You can also suggest a better solution not necessarily using this type of script. I thought if I can get a script to automate the reset if there is a timeout.

          Looking forward to your response

          2+
        • #348218
           Michael Pietroforte 
          Keymaster
          • Topics: 142
          • Replies: 345
          Post count: 1090
          Member Points: 8,044
          Rank: Level 1

          First of all, if the network type is set to Public on a domain member, it usually means that the authentication failed with a domain controller. This is serious issue for a server. You want to find the cause of this problem. Resetting network adapters is not the solution to the problem as this can also cause all kinds of problems. Check the event log for errors to find out what causes the problem.

          Second, if the remote machine is not authenticated in the domain, you can’t access it anymore through PowerShell remoting. Thus, resetting the network adapters remotely from a central location is problematic. I guess a workaround could be to configure the machines as workgroup computers for PowerShell remoting. But this is is not good for security and I don’t recommend it. Thus, I recommend running the script on the problematic servers. If you want to manage the scripts from a central location, you can work with remote jobs. This allows you to view the result at your local console.

          Third, I wouldn’t use ping for this purpose. I would rather read the network type directly:

          You can test the script by temporarily removing the machine from the network.

          2+
        • #348240
           PNN 
          Participant
          • Topics: 1
          • Replies: 6
          Post count: 18
          Member Points: 184
          Rank: Level 1

          Yea, there is an issue with domain authentication but I have checked the logs, DNS entries and can’t find what causes the issue. The good thing is that this issue occurs frequently in servers in a particular VM host meaning it can be isolated and further troubleshooting done. I would appreciate whatever tips to diagnose and fix this persistent issue.

          I need the servers to be in the domain for security purposes. Am not so familiar with remote jobs but I will check your link and research on it more. How about the issue of sending email? We are using office365 which means internet connection is vital for success.

          2+
        • #348960
           Michael Pietroforte 
          Keymaster
          • Topics: 142
          • Replies: 345
          Post count: 1090
          Member Points: 8,044
          Rank: Level 1

          If the problem only exists on a particular host, it might be a hardware issue. I would move one of the servers to another host and see if the problems reoccurs. If it doesn’t, I would replace the network adapter on the problematic host.

          To send an email via the Office 365 SMTP server you can use this code:

          2+
        • #349663
           PNN 
          Participant
          • Topics: 1
          • Replies: 6
          Post count: 18
          Member Points: 184
          Rank: Level 1

          Thanks Michael. Yes I will get to the root of this problem and revert here. Thanks for all your help

          2+
    • #345251
       PNN 
      Participant
      • Topics: 1
      • Replies: 6
      Post count: 18
      Member Points: 184
      Rank: Level 1

      Additionally, I have a list of servers that need to be routinely checked for uptime say daily. I am thinking of having a csv file from which the script can check for each server and give a status for all in an email

      0
  • #340455
     Karim Buzdar 
    Moderator
    • Topics: 26
    • Replies: 90
    Post count: 285
    Member Points: 6,620
    Rank: Level 1

    Hi PNN,

    Does the solution help?

    Thank you,

    2+
    • #345248
       PNN 
      Participant
      • Topics: 1
      • Replies: 6
      Post count: 18
      Member Points: 184
      Rank: Level 1

      Hi Karim

      The solution is not working as it should. See my reply to Michael.

      2+

You must be logged in to reply to this topic.

CONTACT US

Please ask IT administration questions in the forum. Any other messages are welcome.

Sending
© 4sysops 2006 - 2018

Log in with your credentials

or    

Forgot your details?

Create Account