Solved

How to use powershell to monitor multiple application pools on single server with email notification

Posted on 2015-02-05
12
259 Views
Last Modified: 2015-06-23
Hi Experts,
I need a powershell script that able to perform monitoring on multiple application pools on a single server with email notification.  Would appreciate if any experts could provide assistance.  Thanks.

Basically i will schedule a job to run at interval of 5mins to perform monitoring with the following logic:-
1) Monitor multiple application pools status on single server.
2) If application pools failed or not started, attempt to start-up for 3 times.
3) If it failed for 3 times, send email notification to administrator with failed application pool listed for further checking.
4) The notification should only send one time, or else it may flood the mailbox (As the monitoring job is scheduled to run every 5mins).

Regards,
Kung Hui
0
Comment
Question by:kunghui80
12 Comments
 
LVL 26

Expert Comment

by:Dan McFadden
ID: 40590894
This is more of an IIS item.  I recommend that you configure all the AppPools that you want to monitor, for Rapid-Fail Protection.

Reference Link:  http://www.iis.net/configreference/system.applicationhost/applicationpools/add/failure

1. What you want to do is configure the Rapid-Fail Protection as per your definition above.
2. In the "Shutdown Executable" option, add "powershell.exe"
3. In the "Shutdown Executable Parameters" option, add "C:\The-Local-Path-To-Your-Script\SendMail.ps1"

The powershell command to send an email is:

send-mailmessage -SmtpServer "YourSmtpRelayServer.here" -Priority High -To "your.email-address@domain.com" -From "IIS.AppPool-Failure@admin.domain.com" -Subject "Email Subject" -Body "Email Body"

Open in new window


An example screen shot:

RapidFailProtection.png
I would also enable all options for Recycling > "Generate Recycle Event Log entry."   This way you will also get an Application Event Log entry for any and all App Pool recycle/restarts.

It would also be advisable to do regular analysis of your http logs and the HttpError logs.

Dan
0
 
LVL 2

Author Comment

by:kunghui80
ID: 40592839
Hi Dan,
Thanks for feedback.  I have over hundreds of IIS servers in our environment and majority are not open up for SMTP relay which prevent us sending out email from server itself due to some security policy.

Thus, we have to think of alternative solutions which make use of powershell to pool the status of application pools from each servers instead and notify us on the failure.

Regards,
Kung Hui
0
 
LVL 76

Expert Comment

by:arnold
ID: 40624325
What is the server open to? do the server aggregate their event logs to a single server that does have the ability to mailout? Is SNMP available on those servers such that evntwin/evntcmd can be used to establish a map between an event and an SNMPTRAP event?
This will be a trigger as soon as it occurs versus depending on your check cycle as well as the order of your checks.

Are the servers currently being monitored by zabbix, nagios, hp openview, sitescope, etc.?
0
 
LVL 9

Expert Comment

by:Veerappan Sundaram
ID: 40625024
Kung Hui,

Please let me know the email server you have? e.g., Microsoft Exchange server, Qmail, lotus Notes, etc.

SMTP relay is not blocked in many companies. But if you have your IIS servers and Email servers in LAN (Local Area Network) and if they are part of the same Active Directory domain, then you should be able to send email through one of your email servers.

In the worst case scenario, you may need to add your IIS server IPs in "SMTP connections allow list", if SMTP connections are also restricted.

Thanks,
Veera.
0
 
LVL 2

Author Comment

by:kunghui80
ID: 40625034
Hi All,
Thank you for attend to this question.  All our productions servers does not allow SMTP relay (or rather I would say those servers are not in SMTP relay allow list).  At such, I'm using one of the monitoring server which has been granted for SMTP relay to perform monitoring using powershell script.

My question here would be very straight forward - To monitor application state using powershell, instead of using other methods to achieve the same purpose.

Basically i will schedule a job to run at interval of 5mins to perform monitoring with the following logic:-
 1) Monitor multiple application pools status on list of IIS servers.
 2) If application pools failed or not started, attempt to start-up for 3 times (1 time also will do).
 3) If it failed for 3 (or 1) times, send email notification to administrator with failed application pool listed for further checking.
 4) The notification should only send one time, or else it may flood the mailbox (As the monitoring job is scheduled to run every 5mins).

Thanks all!
0
Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

 
LVL 13

Expert Comment

by:Greg Hejl
ID: 40625847
Here you go:

http://www.paessler.com/manuals/prtg/perfcounter_iis_application_pool_sensor

This will also give you trend analysis
0
 
LVL 2

Author Comment

by:kunghui80
ID: 40627187
Hi Greg,
URL given looks more like a product.  What i needed is just some powershell script to achieve the requirement.  Thanks.
0
 
LVL 13

Expert Comment

by:Greg Hejl
ID: 40627242
it is a product.  that i used at my SaaS/webhosting company. it can monitor and manage your environment and execute powershell, vbscripts, etc to do whatever you want to heal your web applications.
0
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
ID: 40627347
what you are after is actually an enterprise infrastructure monitoring solution, something like what Whatsup does. see below.

http://www.whatsupgold.com/products/whatsup-gold-application-performance-monitor.aspx

basically, if it is for critical business, you can't expect running a single monitoring script in a loop to efficiently monitor your IIS. be aware that any task to do in the script must be executed in a sequence, which means it can't monitor while maintaining and vice versa. you may see significant performance decrease if you run too many this kind of scripts at the same time.
0
 
LVL 2

Accepted Solution

by:
kunghui80 earned 0 total points
ID: 40838353
Closing case, no perfect solutions to address the question.
0
 
LVL 2

Author Closing Comment

by:kunghui80
ID: 40845992
Self-closing case with no perfect solution received.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now