Add ability to suppress notificiations IPMonitor
This commit is contained in:
@@ -153,13 +153,20 @@ namespace IPMonitor
|
||||
try{Thread.Sleep(TIMEOUT_BETWEEN_ATTEMPTS);}catch{;}
|
||||
continue;
|
||||
}
|
||||
address = GetHttpRequest(request);
|
||||
if(null==address)
|
||||
HttpNetResponse response = HttpNetRequest.GetRequestNoEncodingV7(request);
|
||||
if(!response.Success)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request failed {0}. Will retry after {1} (ms) ",request,TIMEOUT_BETWEEN_ATTEMPTS));
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"Request {request} failed with {response.StatusCode}. Will retry after {TIMEOUT_BETWEEN_ATTEMPTS} (ms) ");
|
||||
try{Thread.Sleep(TIMEOUT_BETWEEN_ATTEMPTS);}catch{;}
|
||||
continue;
|
||||
}
|
||||
address = response.ResponseString;
|
||||
if(String.IsNullOrEmpty(address))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"Request {request} received an empty response. Will retry after {TIMEOUT_BETWEEN_ATTEMPTS} (ms) ");
|
||||
try{Thread.Sleep(TIMEOUT_BETWEEN_ATTEMPTS);}catch{;}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(null==address)
|
||||
{
|
||||
@@ -189,31 +196,6 @@ namespace IPMonitor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an HttpRequest and receives the response string. Used by GetPublicIPAddress
|
||||
/// </summary>
|
||||
/// <param name="ipAddress"></param>
|
||||
public static String GetHttpRequest(String strRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
WebRequest request = WebRequest.Create(strRequest);
|
||||
using WebResponse response = request.GetResponse();
|
||||
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
return stream.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request {strRequest} Failed with {1}",exception.ToString()));
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates ZoneEdit with the given ipaddress.
|
||||
/// </summary>
|
||||
@@ -342,6 +324,14 @@ namespace IPMonitor
|
||||
String smsUserName = GlobalConfig.Instance.Configuration["sms_smsusername"];
|
||||
String smsPassword = GlobalConfig.Instance.Configuration["sms_smspassword"];
|
||||
String[] smsRecipients = GlobalConfig.Instance.Configuration["sms_smsrecipients"].Split(',');
|
||||
bool sendNotifications = bool.Parse(GlobalConfig.Instance.Configuration["send_notifications"]);
|
||||
|
||||
if(!sendNotifications)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"Not sending Message '{message}' to {GlobalConfig.Instance.Configuration["sms_smsrecipients"]} because notifications are disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
SMSClient.SendSMSEmail(message, smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"send_notifications" : "false",
|
||||
"working_folder" : "/ipaddress",
|
||||
"sms_smtpaddress" : "smtp.gmail.com",
|
||||
"sms_smsusername" : "skessler1964@gmail.com",
|
||||
|
||||
Reference in New Issue
Block a user