Hi All,
I have created console application to verify the installed service status running or stopped.
Below are code.
1) Add below the keys in your application.
<add key ="ServicesName " value="SCardSvr, SNMPTRAP, Appinfo"></add>
<add key ="ToEmail" value="abc@gmail.com"></add>
<add key ="ProjectName" value="HIP Teva"/>
<add key ="EnvironmentName" value="Test"/>
<add key ="FromEmail" value="abc@gmail.com"/>
<! --Email body in in key-->
<add key="EmailTemplate " value="Hi %ToEmail% , <br><br>Please verify below service on %environmentName% environment . <br> <br> %stoppedServices% Sever IP address : %serverIP% <br><br><br> Thanks"></add>
2) Add
System. ServiceProcess
on your project references from NuGet
3) Add below code.
{
{
var serviceNamelist = serviceNamesCommaseparated.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// To Loop through
{
{
{
}
}
}
{
//Send Emial to the admin and also log in log file
}
}
}
{
// Verify server name is installed or not in server
{
{
}
}
{
}
}
{
{
StreamWriter log ;
{
}
{
}
// Write to the file:
// Close the stream:
}
{
}
}
{
{
MailMessage mm = new MailMessage( );
mm.Body = EmailTemplate.Replace("%ToEmail%", ToEmail).Replace("%environmentName%", environmentName).Replace("%stoppedServices%", stoppedServices).Replace("%serverIP%", serverIP);
foreach (var RecepientEmail in fRecepientEmail.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { mm.To.Add(RecepientEmail); }
}
{
}
}
I have added to all services that need to be verify in web. config file. If services are stopped or postponed then application send the email in provided email.
Thanks for reading.
No comments:
Post a Comment