Initial version of the .NET HostAvailabilityMonitor.
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
# Host Availability Monitor (.NET Framework 4.8)
|
||||
|
||||
Robuste Windows-Console-Anwendung für **Windows Server 2019** zur Überwachung von UNC-Fileshares, HTTP/HTTPS-Endpunkten, SFTP-Servern, TCP-Ports und optional ICMP/Ping.
|
||||
|
||||
Die Anwendung ist für den Einsatz mit dem **Task Scheduler** gedacht und schreibt:
|
||||
|
||||
- ein tägliches Rolling-Logfile
|
||||
- Einträge ins **Windows Application Event Log**
|
||||
- Statusinformationen in eine lokale Statusdatei
|
||||
- Benachrichtigungs-E-Mails bei Fehlern und optional bei Recovery
|
||||
|
||||
## Warum .NET Framework 4.8?
|
||||
|
||||
Windows Server 2019 enthält .NET Framework 4.7.2 und unterstützt als separat installierbare Version .NET Framework 4.8. Das macht .NET Framework 4.8 für dieses Umfeld zu einer sehr passenden Zielplattform.
|
||||
|
||||
## Features
|
||||
|
||||
- **Zieltypen**
|
||||
- UNC / SMB (`\\server\share`)
|
||||
- HTTP / HTTPS (`http://...`, `https://...`)
|
||||
- SFTP (netzwerktechnisch per TCP-Port 22 oder konfiguriertem Port)
|
||||
- TCP (`tcp://server:8443`)
|
||||
- ICMP (`icmp://server`)
|
||||
- Optional auch **Plain Hostnames**:
|
||||
- mit `Port` => TCP-Check
|
||||
- ohne `Port` => ICMP-Check
|
||||
- **Tägliche Logrotation** über Dateiname `host-availability-monitor-yyyy-MM-dd.log`
|
||||
- **Log-Retention** konfigurierbar, Standard: 5 Tage
|
||||
- **Event Log** in `Application`
|
||||
- **E-Mail-Benachrichtigung** bei Ausfall und optional bei Recovery
|
||||
- **Cooldown / State Change Logik** gegen Mail-Spam
|
||||
- **Resiliente Dateiverarbeitung** mit atomarem Schreiben der Statusdatei
|
||||
- Für **Task Scheduler** geeignet
|
||||
|
||||
## Projektstruktur
|
||||
|
||||
```text
|
||||
host-availability-monitor-net48/
|
||||
├── HostAvailabilityMonitor.sln
|
||||
├── README.md
|
||||
├── Dokumentation.md
|
||||
├── .gitignore
|
||||
├── .editorconfig
|
||||
├── scripts/
|
||||
│ ├── build-release.ps1
|
||||
│ └── register-event-source.ps1
|
||||
└── src/
|
||||
└── HostAvailabilityMonitor/
|
||||
├── App.config
|
||||
├── appsettings.json
|
||||
├── HostAvailabilityMonitor.csproj
|
||||
├── Program.cs
|
||||
├── Configuration/
|
||||
├── Logging/
|
||||
├── Monitoring/
|
||||
├── Notifications/
|
||||
├── Properties/
|
||||
└── State/
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
### Visual Studio
|
||||
|
||||
- Solution `HostAvailabilityMonitor.sln` öffnen
|
||||
- Configuration `Release`
|
||||
- Build starten
|
||||
|
||||
### MSBuild
|
||||
|
||||
```powershell
|
||||
msbuild .\HostAvailabilityMonitor.sln /p:Configuration=Release /p:Platform="Any CPU"
|
||||
```
|
||||
|
||||
Alternativ liegt das Skript `scripts/build-release.ps1` bei.
|
||||
|
||||
## Deployment
|
||||
|
||||
1. Projekt im Release-Modus bauen
|
||||
2. Den Inhalt von `src\HostAvailabilityMonitor\bin\Release\` auf den Server kopieren
|
||||
3. `appsettings.json` anpassen
|
||||
4. Optional Event Source registrieren:
|
||||
|
||||
```powershell
|
||||
.\scripts\register-event-source.ps1 -Source "HostAvailabilityMonitor" -LogName "Application"
|
||||
```
|
||||
|
||||
5. Task Scheduler anlegen, z. B. alle 30 Minuten
|
||||
|
||||
## Konfiguration
|
||||
|
||||
Die Anwendung nutzt **`appsettings.json`** als Anwendungs-Konfiguration.
|
||||
|
||||
Wichtig für .NET Framework 4.8 in dieser Umsetzung:
|
||||
|
||||
- JSON muss **strict valid** sein
|
||||
- keine Kommentare
|
||||
- keine trailing commas
|
||||
|
||||
### Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"ApplicationName": "HostAvailabilityMonitor",
|
||||
"Runtime": {
|
||||
"MaxConcurrency": 4,
|
||||
"DefaultValidateUncPathAccess": false,
|
||||
"NonZeroExitCodeOnAnyFailure": false,
|
||||
"NonZeroExitCodeOnExecutionError": true,
|
||||
"StateDirectory": "state"
|
||||
},
|
||||
"Logging": {
|
||||
"LogDirectory": "logs",
|
||||
"FilePrefix": "host-availability-monitor",
|
||||
"RetentionDays": 5
|
||||
},
|
||||
"EventLog": {
|
||||
"Enabled": true,
|
||||
"LogName": "Application",
|
||||
"Source": "HostAvailabilityMonitor",
|
||||
"CreateSourceIfMissing": false,
|
||||
"WriteSuccessEntries": false,
|
||||
"WriteSummaryEntries": true
|
||||
},
|
||||
"Email": {
|
||||
"Enabled": false,
|
||||
"SmtpHost": "smtp.example.local",
|
||||
"SmtpPort": 25,
|
||||
"UseSsl": false,
|
||||
"Username": "",
|
||||
"Password": "",
|
||||
"From": "monitor@example.local",
|
||||
"To": ["ops@example.local"],
|
||||
"SubjectPrefix": "[HostAvailabilityMonitor]",
|
||||
"SendOnFailure": true,
|
||||
"SendOnRecovery": true,
|
||||
"OnlyOnStateChange": true,
|
||||
"CooldownMinutes": 0,
|
||||
"TimeoutSeconds": 30
|
||||
},
|
||||
"Targets": [
|
||||
{
|
||||
"Name": "Internes Fileshare 1",
|
||||
"Endpoint": "\\\\internerserver1\\share1",
|
||||
"TimeoutSeconds": 8,
|
||||
"ValidateUncPathAccess": false,
|
||||
"Enabled": true
|
||||
},
|
||||
{
|
||||
"Name": "Externe Webseite",
|
||||
"Endpoint": "https://host1.de/url",
|
||||
"TimeoutSeconds": 10,
|
||||
"HttpMethod": "HEAD",
|
||||
"Enabled": true
|
||||
},
|
||||
{
|
||||
"Name": "SFTP Partner A",
|
||||
"Endpoint": "sftp://partner.example.local/inbound",
|
||||
"TimeoutSeconds": 10,
|
||||
"Port": 22,
|
||||
"Enabled": true
|
||||
},
|
||||
{
|
||||
"Name": "Custom TCP Service",
|
||||
"Endpoint": "tcp://host2.example.local:8443",
|
||||
"TimeoutSeconds": 10,
|
||||
"Enabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Task Scheduler
|
||||
|
||||
**Program/script**
|
||||
|
||||
```text
|
||||
C:\Tools\HostAvailabilityMonitor\HostAvailabilityMonitor.exe
|
||||
```
|
||||
|
||||
**Start in**
|
||||
|
||||
```text
|
||||
C:\Tools\HostAvailabilityMonitor
|
||||
```
|
||||
|
||||
**Optional arguments**
|
||||
|
||||
```text
|
||||
C:\Tools\HostAvailabilityMonitor\appsettings.json
|
||||
```
|
||||
|
||||
## Logging
|
||||
|
||||
- Dateilog: `logs\host-availability-monitor-yyyy-MM-dd.log`
|
||||
- Retention: Standard 5 Tage
|
||||
- Event Log: `Application`
|
||||
- State-Datei: `state\monitor-state.json`
|
||||
|
||||
## Benachrichtigung
|
||||
|
||||
Benachrichtigung wird nur als erfolgreich markiert, wenn der SMTP-Versand wirklich erfolgreich war. Dadurch bleibt die Cooldown-/State-Change-Logik konsistent.
|
||||
|
||||
## Hinweise
|
||||
|
||||
- Für **UNC-Pfade** kann optional zusätzlich der Pfadzugriff validiert werden. Standardmäßig wird nur die **SMB-Erreichbarkeit** über TCP 445 geprüft.
|
||||
- Für **HTTP/HTTPS** gilt jede empfangene HTTP-Antwort als netzwerktechnisch erreichbar, auch `404` oder `500`.
|
||||
- Für **SFTP** wird bewusst nur die **Port-Erreichbarkeit** geprüft, kein Login und kein Dateizugriff.
|
||||
- Das Anlegen einer neuen Event Source erfordert Administratorrechte. Deshalb ist dafür ein separates Installationsskript beigefügt.
|
||||
|
||||
## Weiterführend
|
||||
|
||||
Details zu Logging, Exit Codes, Fehlerfällen und Betriebsmodell stehen in [Dokumentation.md](Dokumentation.md).
|
||||
Reference in New Issue
Block a user