public static void Main()
void RunMyServer(MonitorTask task, ServerStatus serverStatus)
MyServerParams taskParams = task.TaskParams as MyServerParams;
throw new Exception("Invalid BaseParams object");
ServerInfo serverInfo = GetServerInfo(task);
if (serverInfo == null || serverInfo.DatabaseInfo == null)
throw new Exception($"Unable to obtain server info for Task: {task.Task.Id}");
bool hasDatabaseInfo = serverInfo.DatabaseInfo.Length > 0;
ServerMonitorCommon.Geotab.ObjectModel.Server currentServer;
if (!serversProcessedDictionary.TryGetValue(task.Task.Server.Id, out currentServer))
ServerMonitorCommon.Geotab.ObjectModel.Server serverToUpdate = new ServerMonitorCommon.Geotab.ObjectModel.Server(task.Task.Server.Id, task.Task.Server.ServerAddress, (ServerMonitorCommon.Geotab.ServerType)task.Task.Server.Type, (ServerMonitorCommon.Geotab.PremiumServerType)task.Task.Server.PremiumType, serverInfo.ServerLocation);
currentServer = serverBridge.GetFromId(serverToUpdate.Id);
if (currentServer != null)
if (currentServer.ServerLocation == null || !string.Equals(currentServer.ServerLocation, serverToUpdate.ServerLocation))
serverBridge.Set(serverToUpdate, serverToUpdate);
serversProcessedDictionary.Add(serverToUpdate.Id, serverToUpdate);
serverStatus.Status = ServerStatusType.Up;
double loadFactorInfiniteLimit = 9999999;
if (taskParams.checkLoadFactor && serverInfo.LoadFactor >= loadFactorInfiniteLimit)
serverStatus.Status = ServerStatusType.Warning;
serverStatus.ErrorMsg += string.Format("High load factor: {0} ", serverInfo.LoadFactor) + Environment.NewLine;
foreach (var info in serverInfo.DatabaseInfo)
if (!string.IsNullOrEmpty(info.Comment))
serverStatus.ErrorMsg += info.Name + ": " + info.Comment + Environment.NewLine;
if (hasDatabaseInfo && serverStatus.Status == ServerStatusType.Up && taskParams.checkLagTime)
double lagTimeLimit = taskParams.lagTimeLimit;
foreach (var info in serverInfo.DatabaseInfo)
int deviceCount = info.BillableDeviceCount != null ? info.BillableDeviceCount.Value : info.DeviceCount.GetValueOrDefault(0);
if (info.ProcessingStatus != ProcessingStatus.AfterHoursReprocessing && (info.LagTime.TotalMilliseconds > lagTimeLimit && info.LagTime.TotalMilliseconds > new TimeSpan(0, 30, 0).TotalMilliseconds) || (info.LagTime.TotalMilliseconds == -4 && deviceCount > 0))
serverStatus.Status = ServerStatusType.Warning;
serverStatus.ErrorMsg += string.Format("High database lag time: {0}: {1} ", info.Name, info.LagTime.TotalMilliseconds) + Environment.NewLine;
if (!string.IsNullOrEmpty(info.Comment))
serverStatus.ErrorMsg += info.Name + ": " + info.Comment + Environment.NewLine;
int consecutiveExcelFailureLimit = taskParams.consecutiveExcelFailuresLimit;
if (taskParams.checkConsecutiveExcelFailures && serverInfo.ConsecutiveExcelFailures >= consecutiveExcelFailureLimit)
serverStatus.Status = ServerStatusType.Warning;
serverStatus.ErrorMsg += string.Format("Excel failure count exceeded: {0} ", serverInfo.ConsecutiveExcelFailures) + Environment.NewLine;
if (settings.SaveMyServerData && (DateTime.UtcNow - task.LastCommitTime) > settings.MyServerInfoCommitInterval)
task.LastCommitTime = DateTime.UtcNow;
MyServerData data = MyServerDataFromInfo(task.Task.Server, serverInfo);
object bigDataObject = MyServerFunctions.GetFullMyServerInfo(task.Task.Server.ServerAddress);
if (bigDataObject != null)
GetBigDataUploadItemsFromServerInfoObjects(SqlStore, bigDataObject, task.Task.Server.ServerAddress, ref myServerInfoList, ref myServerDatabaseInfoList, ref myServerReplicaInfoList, ref myServerInfoComGovList, ref myServerDatabaseInfoComGovList, ref myServerReplicaInfoComGovList);