public static CheckResult Check(string[] args) { CheckResult I2CheckResult = new CheckResult(); I2CheckResult = Icinga2Handler.Parse(I2CheckResult, args); return I2CheckResult; }
public static CheckResult Parse(CheckResult I2CheckResult, string[] args) { int returncode = 0; returncode = Handler.ParseArgs(returncode, args); // Return if something is not ok. if (returncode > (int)ServiceState.ServiceOK) { I2CheckResult.State = ServiceState.ServiceUnknown; return I2CheckResult; } // Inventory is blocked from running at the same time as other checks, thus it is run first if specified. if (Settings.bDoInventory == true && Settings.strInventoryFormat == "i2conf") { returncode = Inventory.OutputI2Conf(); I2CheckResult.State = ServiceState.ServiceOK; return I2CheckResult; } else if (Settings.bDoInventory == true) { I2CheckResult.Output = "Unknown inventory, format: '" + Settings.strInventoryFormat + "', level: '" + Settings.strInventoryLevel + "'"; I2CheckResult.State = ServiceState.ServiceUnknown; return I2CheckResult; } if (Settings.bDoCheckServices == true) { returncode = Checks.Services(returncode); } I2CheckResult.State = (ServiceState)returncode; I2CheckResult = HandleIcinga2Text(I2CheckResult, returncode); return I2CheckResult; }
public static CheckResult HandleIcinga2Text(CheckResult I2CheckResult, int returncode) { // ORDER the output string output = ""; output = Checks.outputServices; // Handle returncode and exit with proper messages. if (returncode == (int)ServiceState.ServiceOK) { output = "OK: " + output; } else if (returncode == (int)ServiceState.ServiceWarning) { output = "WARNING: " + output; } else if (returncode == (int)ServiceState.ServiceCritical) { output = "CRITICAL: " + output; } else if (returncode == (int)ServiceState.ServiceUnknown) { output = "UNKNOWN: " + output; } else { output = "UNHANDLED: " + output; } string outputLong = ""; if (PerfData.iNumberOfServices > 1 && Settings.bDoHideLongOutput == false) { int x = 1; foreach (string outputS in Checks.listServiceOutput) { if (x < Checks.listServiceOutput.Count) { outputLong = outputLong + outputS + "\n"; } else { outputLong = outputLong + outputS; } x++; } } string perfdata = ""; foreach (string outputP in Checks.listPerfData) { perfdata = perfdata + outputP; } if (Settings.bDoHideLongOutput) { I2CheckResult.Output = output; } else { if (PerfData.iNumberOfServices > 1) output = output + outputLong; I2CheckResult.Output = output; } I2CheckResult.PerformanceData = perfdata; return I2CheckResult; }
private static int HandleExitText(int returncode, bool do_hide_long_output) { // ORDER the output string output = ""; if ((errorAppPools == true) && (errorSites == false)) { output = outputAppPools + outputSites; } else if ((errorAppPools == false) && (errorSites == true)) { output = outputSites + outputAppPools; } else { output = outputSites + outputAppPools; } // Handle returncode and exit with proper messages. if (returncode == (int)ServiceState.ServiceOK) { output = "OK: " + output; } else if (returncode == (int)ServiceState.ServiceWarning) { output = "WARNING: " + output; } else if (returncode == (int)ServiceState.ServiceCritical) { output = "CRITICAL: " + output; } else if (returncode == (int)ServiceState.ServiceUnknown) { output = "UNKNOWN: " + output; } else { output = "UNHANDLED: " + output; } string outputLong = ""; if (do_hide_long_output == false) { int x = 1; if (iNumberOfSites > 1) { foreach (string outputW in listSiteOutput) { if (x < listSiteOutput.Count) { outputLong = outputLong + outputW + "\n"; } else { if (iNumberOfAppPools > 0) { outputLong = outputLong + outputW + "\n"; } else { outputLong = outputLong + outputW; } } x++; } } int y = 1; if (iNumberOfAppPools > 1) { foreach (string outputA in listAppPoolOutput) { if (y < listAppPoolOutput.Count) { outputLong = outputLong + outputA + "\n"; } else { outputLong = outputLong + outputA; } y++; } } } string perfdata = ""; foreach (string outputP in listPerfData) { perfdata = perfdata + outputP; } if (do_i2 == true) { CheckResult IcingaOutput = new CheckResult(); IcingaOutput.State = (ServiceState)returncode; if (do_hide_long_output == false) { IcingaOutput.Output = output + outputLong; } else { IcingaOutput.Output = output; } IcingaOutput.PerformanceData = perfdata; } else { Console.Write(output); if ((iNumberOfAppPools > 1 || iNumberOfSites > 1) && do_hide_long_output == false) Console.Write("\n" + outputLong); Console.Write(" | " + perfdata); } return returncode; }