72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace BizTalkCheckmkPulse
|
|
{
|
|
/// <summary>
|
|
/// Einstiegspunkt des Checkmk Local Checks.
|
|
/// </summary>
|
|
internal static class Program
|
|
{
|
|
/// <summary>
|
|
/// Laedt die Konfiguration, fuehrt die Probes aus und schreibt Checkmk-Zeilen nach STDOUT.
|
|
/// </summary>
|
|
/// <param name="args">Kommandozeilenargumente wie <c>--self-test</c> oder <c>--environment</c>.</param>
|
|
/// <returns>Immer 0, damit Diagnosefehler als UNKNOWN-Service statt als kaputte Agent-Sektion erscheinen.</returns>
|
|
private static int Main(string[] args)
|
|
{
|
|
MonitoringOptions options = null;
|
|
|
|
try
|
|
{
|
|
Console.OutputEncoding = new UTF8Encoding(false);
|
|
options = MonitoringOptions.Load(args);
|
|
var formatter = new CheckmkLocalFormatter(options);
|
|
|
|
if (options.SelfTest)
|
|
{
|
|
foreach (var line in formatter.FormatSelfTest())
|
|
{
|
|
Console.WriteLine(line);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
var result = new ProbeResult();
|
|
var wmiProbe = new WmiBizTalkProbe(options);
|
|
wmiProbe.Query(result);
|
|
|
|
// Der SQL-Test verwendet bewusst dieselbe Windows-Identitaet wie der Checkmk-Agent.
|
|
var sqlProbe = new SqlConnectivityProbe(options);
|
|
sqlProbe.Query(result);
|
|
|
|
if (options.ProbeEventLog)
|
|
{
|
|
var eventLogProbe = new EventLogProbe(options);
|
|
eventLogProbe.Query(result);
|
|
}
|
|
|
|
foreach (var line in formatter.Format(result))
|
|
{
|
|
Console.WriteLine(line);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var fallbackOptions = options ?? new MonitoringOptions();
|
|
var formatter = new CheckmkLocalFormatter(fallbackOptions);
|
|
foreach (var line in formatter.FormatFatal("BizTalk Checkmk Pulse failed: " + ex.GetType().Name + ": " + ex.Message))
|
|
{
|
|
Console.WriteLine(line);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|