public MonitorState GetCurrentState() { PingCollectorResult pingResult = Ping(); CurrentAgentValue = pingResult; MonitorState currentState = new MonitorState() { ForAgent = Address, CurrentValue = pingResult.PingTime, CurrentValueUnit = "ms" }; if (pingResult.PingTime > -1) { if (pingResult.PingTime > TimeOutMS) { currentState.State = CollectorState.Error; currentState.RawDetails = string.Format("Operation timed out! Max time allowed: {0}ms, {1}", TimeOutMS, pingResult.ResponseDetails); } else if (pingResult.PingTime > MaxTimeMS) { currentState.State = CollectorState.Warning; currentState.RawDetails = string.Format("Operation did not finished in allowed time! Excepted time: {0}ms, {1}", MaxTimeMS, pingResult.ResponseDetails); } else if (pingType == PingCollectorType.HTTP && HTMLContentContain != null && pingResult.ResponseContent.Trim().Length > 0 && HTMLContentContain.Trim().Length > 0 && !pingResult.ResponseContent.Contains(HTMLContentContain)) { currentState.State = CollectorState.Warning; currentState.RawDetails = string.Format("The returned HTML does not contain the specified string '{0}'", HTMLContentContain); } else { currentState.State = CollectorState.Good; } } else { currentState.State = CollectorState.Error; if (pingResult.ResponseDetails == "No such host is known") { currentState.CurrentValue = "Host not found"; currentState.CurrentValueUnit = ""; } currentState.RawDetails = pingResult.ResponseDetails; } return(currentState); }
public CollectorState GetState(PingCollectorResult pingResult) { CollectorState result = CollectorState.Good; if (pingResult.PingTime > -1) { if (pingResult.PingTime > TimeOutMS) { result = CollectorState.Error; pingResult.ResponseDetails = string.Format("Operation timed out! Max time allowed: {0}ms, {1}", TimeOutMS, pingResult.ResponseDetails); } else if (pingResult.PingTime > MaxTimeMS) { result = CollectorState.Warning; pingResult.ResponseDetails = string.Format("Operation did not finished in allowed time! Excepted time: {0}ms, {1}", MaxTimeMS, pingResult.ResponseDetails); } else if (pingType == PingCollectorType.HTTP && HTMLContentContain != null && pingResult.ResponseContent.Trim().Length > 0 && HTMLContentContain.Trim().Length > 0 && !pingResult.ResponseContent.Contains(HTMLContentContain)) { result = CollectorState.Warning; pingResult.ResponseDetails = string.Format("The returned HTML does not contain the specified string '{0}'", HTMLContentContain); } else { result = CollectorState.Good; } } else { result = CollectorState.Error; } return(result); }