//makes sure the checkresults are written correctly or throw exceptions. public static void ValidateCheckresult(Checkresults checkresults) { int count = checkresults.Count; if (count == 0) { throw new ApplicationException("There is no checkresult in the list of checkresults."); } foreach (Checkresultitem checkresultitem in checkresults) { List <string> listtype = new List <string> { "host", "service" }; string type = checkresultitem.Checkresult.Type; if (!listtype.Contains(type)) { throw new ApplicationException("Type can only be 'host' or 'service'"); } } foreach (Checkresultitem checkresultitem in checkresults) { List <string> liststate = new List <string> { "0", "1", "2", "3" }; string state = checkresultitem.State; if (!liststate.Contains(state)) { throw new ApplicationException("State can only be '0', '1','2','3'"); } } }
public static void LogResponse(int errorLevel, string description) { Checkresults checkresults = new Checkresults(); checkresults.Add(new Checkresultitem(new Checkresult("service"), "172.20.22.242", "Log File 03122831", (errorLevel - 1).ToString(), description)); NagiosClient.ReportError(checkresults); }
public static void ReportError(Checkresults checkresultitems) { //Generate the checkresults array to Json with each checkresult Checkresultitem[] checkresults = checkresultitems.ToArray(); var checkresultswrapper = new { checkresults }; string json = JsonConvert.SerializeObject(checkresultswrapper); ValidateCheckresult(checkresultitems); NRDPApi api = new NRDPApi(BeGlobalData.ApiConfig); // submit the json, token and submitcheck command ApiResponse <Resultwrapper> response = api.NrdpPostWithHttpInfo(token, "submitcheck", json); }
public static void DBSendDataCheckResponse() { using (DBConn DB = new DBConn()) { // Collect count if (DB.Connect()) { // Temporary variables for count of rows in SendData string sSQL = "SELECT count(*) AS Count FROM SendData"; long count = 0; DB.OpenCursor(sSQL); if (DB.HasRows()) { while (DB.Fetch()) // Fetch row-by-row { count = DB.Col2Long("Count"); } } // 0 - 9: ok 10-24: Warning 25+: Critical Checkresults checkresults = new Checkresults(); if ((count >= 10) && (count < 25)) { if (curstate != "1") { curstate = "1"; checkresults.Add(new Checkresultitem(new Checkresult("service"), "172.20.22.242", "SendData", "1", "Warning: SendData has more than 10 rows!")); NagiosClient.ReportError(checkresults); } } else if (count >= 25) { if (curstate != "2") { curstate = "2"; checkresults.Add(new Checkresultitem(new Checkresult("service"), "172.20.22.242", "SendData", "2", "Critical: SendData has more than 25 rows!")); NagiosClient.ReportError(checkresults); } } else { if (curstate != "0") { curstate = "0"; checkresults.Add(new Checkresultitem(new Checkresult("service"), "172.20.22.242", "SendData", "0", "SendData is Ok!")); NagiosClient.ReportError(checkresults); } } } } }