Syslog Server/Client dan UDP Relay berdasarkan .NET Framework Class System.Net.Sockets ke mode Pekerjaan Latar Belakang.
Dokumentasi yang digunakan (soket udp): metanit.com
Dokumentasi yang digunakan (pesan syslog): devconnected.com
Server syslog pemfaktoran ulang kode sumber: spiderip.com
Sumber klien udp: cloudbrothers.info
Instal modul dari repositori NuGet:
Install-Module pSyslog - Repository NuGet
Anda harus memiliki repositori NuGet yang terdaftar:
Register-PSRepository - Name " NuGet " - SourceLocation " https://www.nuget.org/api/v2 " - InstallationPolicy Trusted
Atau gunakan modul instal atau perbarui dari repositori GitHub (menggunakan skrip Deploy-pSyslog.ps1 ) gunakan perintah di konsol PowerShell :
Invoke-Expression(New-Object Net.WebClient).DownloadString("https://raw.githubusercontent.com/Lifailon/pSyslog/rsa/Module/Deploy-pSyslog.ps1")
Versi PS yang didukung: 5.1 dan 7.3
Impor modul dan dapatkan daftar perintah:
PS C:UsersLifailon> Import-Module pSyslog
PS C:UsersLifailon> Get-Command -Module pSyslog
CommandType Name Version Source
----------- ---- ------- ------
Function Get-pSyslog 0.6 pSyslog
Function Send-pSyslog 0.6 pSyslog
Function Show-pSyslog 0.6 pSyslog
Function Start-pSyslog 0.6 pSyslog
Function Start-UDPRelay 0.6 pSyslog
Function Stop-pSyslog 0.6 pSyslog
PS C:UsersLifailon> Start-pSyslog -Port 514
PS C:UsersLifailon> Get-pSyslog -Status | Format-List
Status : Running
StartTime : 06.06.2023 1:09:47
StopTime :
PS C:UsersLifailon> Get-pSyslog
PS C:UsersLifailon> Get-pSyslog
Jun 6 01:11:01 zabbix-01 Informational authpriv CRON[3052]: pam_unix(cron:session): session opened for user root by (uid=0)
Jun 6 01:11:01 zabbix-01 Informational cron CRON[3053]: (root) CMD (date >> /dump/zabbix/cron-test-date.txt)
Jun 6 01:11:01 zabbix-01 Informational authpriv CRON[3052]: pam_unix(cron:session): session closed for user root
Jun 6 01:11:03 zabbix-01 Informational daemon multipathd[784]: sda: add missing path
Jun 6 01:11:03 zabbix-01 Informational daemon multipathd[784]: sda: failed to get udev uid: Invalid argument
Jun 6 01:11:03 zabbix-01 Informational daemon multipathd[784]: sda: failed to get sysfs uid: Invalid argument
Jun 6 01:11:03 zabbix-01 Informational daemon multipathd[784]: sda: failed to get sgio uid: No such file or directory
Jun 6 01:11:01 plex-01 Informational user Service[WinRM] Running
...
PS C:UsersLifailon> Stop-pSyslog
PS C:UsersLifailon> Get-pSyslog -Status | Format-List
Status : Stopped
StartTime : 06.06.2023 1:09:47
StopTime : 06.06.2023 1:13:43
Send-pSyslog -Content "Test" -Server 192.168.3.99
Send-pSyslog -Content "Test" -Server 192.168.3.99 -Type Informational -PortServer 514 -PortClient 55514
Gunakan pipeline dan pengiriman ke server rSyslog:
(Get-Service -Name WinRM).Status | Send-pSyslog -Server 192.168.3.102 -Tag Service[WinRM]
Send-pSyslog -Content "test" -Server 192.168.3.99 -PortServer 514
Send-pSyslog -Content "test" -Server 192.168.3.99 -PortServer 514 -Base64
Filter Wireshark: udp.dstport == 514 && ip.src == 192.168.3.100 && !icmp
Server (192.168.3.102): Start-pSyslog -Port 514
Relai (192.168.3.99): Start-UDPRelay -inPort 515 -outIP 192.168.3.102 -outPort 514
Klien (192.168.3.100): Send-pSyslog -Server 192.168.3.99 -PortServer 515 -Content $(Get-Date)
Keluarkan file log ke Objek untuk mengumpulkan metrik
PS C:UsersLifailon> Show-pSyslog -Type Warning -Count
2917
PS C:UsersLifailon> Show-pSyslog -Type Alert -Count
36
PS C:UsersLifailon> Show-pSyslog -Type Critical -Count
5
PS C:UsersLifailon> Show-pSyslog -Type Error -Count
5
PS C:UsersLifailon> Show-pSyslog -Type Emergency -Count
0
PS C:UsersLifailon> Show-pSyslog -Type Informational -Count
15491
Show-pSyslog | Out-GridView
Atau lihat jurnal lama dengan nama file wildcard:
Show-pSyslog -LogFile 05-06 | Out-GridView
Contoh reboot sistem file log: 06-06-2023_reboot.log
Rotasi file log dan tampilkan semua file log dalam 24 jam:
Start-pSyslog -RotationSize 500
Show-pSyslog -Count
Show-pSyslog -Count -LogFile 10-06
Contoh keluaran syslog lokal (menggunakan tail):
Contoh keluaran server pSyslog ke konsol PowerShell: