Add ability to suppress notificiations IPMonitor

This commit is contained in:
2025-04-27 09:20:30 -04:00
parent 7ed8650cc1
commit cebf9f63e6
5 changed files with 34 additions and 32 deletions

14
.vscode/launch.json vendored
View File

@@ -25,6 +25,18 @@
"cwd": "${workspaceFolder}/MarketDataServer",
"console": "internalConsole",
"stopAtEntry": false
}
},
{
"name": ".NET Core Launch (ipmonitor)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/IPMonitor/bin/Debug/net8.0/ipmonitor.dll",
"args": ["IPMONITOR","/FORCE:true"],
"cwd": "${workspaceFolder}/IPMonitor",
"console": "internalConsole",
"stopAtEntry": false
},
]
}

View File

@@ -153,10 +153,17 @@ 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;
}
@@ -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);
}
}

View File

@@ -1,4 +1,5 @@
{
"send_notifications" : "false",
"working_folder" : "/ipaddress",
"sms_smtpaddress" : "smtp.gmail.com",
"sms_smsusername" : "skessler1964@gmail.com",

View File

@@ -11,8 +11,7 @@
<HintPath>..\assemblies\HtmlAgilityPack.dll</HintPath>
</Reference>
<ProjectReference Include="../../Axiom/Axiom.Core/Axiom.Core.csproj" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.3" />
<PackageReference Include="MySql.Data" Version="9.2.0" />

View File

@@ -105,6 +105,6 @@ CRON_DIR_IPMONITOR=/opt/MarketData/IPMonitor
0 0 15 * * cd $CRON_DIR ; /opt/MarketData/MarketData/mk UPDATEFUNDAMENTALS > /dev/null 2>&1
0 0 15 * * cd $CRON_DIR ; /opt/MarketData/MarketData/mk UPDATEHISTORICAL > /dev/null 2>&1
15 0 15 * * cd $CRON_DIR ; /opt/MarketData/MarketData/mk CALCSTICKER /WAITFORCOMPLETION:UPDATEFINANCIALSTATEMENTS,UPDATEFUNDAMENTALS,UPDATEHISTORICAL > /dev/null 2>&1
0 * * * * cd $CRON_DIR_IPMONITOR ; /opt/MarketData/IPMonitor/ipmonitor /FORCE:true > /dev/null 2>&1
0 * * * * cd $CRON_DIR_IPMONITOR ; /opt/MarketData/IPMonitor/ipmonitor IPMONITOR /FORCE:true > /dev/null 2>&1
10,20,30,40,50 * * * * cd $CRON_DIR_IPMONITOR ; /opt/MarketData/IPMonitor/ipmonitor > /dev/null 2>&1