Syslog 伺服器/客戶端和 UDP 中繼基於.NET Framework 類別 System.Net.Sockets到後台作業模式。
使用的文檔(udp套接字): metanit.com
使用的文件(系統日誌訊息): devconnected.com
原始碼重構syslog伺服器: spiderip.com
源udp客戶端: cloudbrothers.info
從 NuGet 儲存庫安裝模組:
Install-Module pSyslog - Repository NuGet
您必須註冊 NuGet 儲存庫:
Register-PSRepository - Name " NuGet " - SourceLocation " https://www.nuget.org/api/v2 " - InstallationPolicy Trusted
或使用 GitHub 儲存庫中的安裝或更新模組(使用腳本Deploy-pSyslog.ps1 )在 powershell 控制台中使用指令:
Invoke-Expression(New-Object Net.WebClient).DownloadString("https://raw.githubusercontent.com/Lifailon/pSyslog/rsa/Module/Deploy-pSyslog.ps1")
支援的 PS 版本: 5.1 和 7.3
導入模組並取得命令清單:
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
使用管道並發送到 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
Wireshark 過濾器: udp.dstport == 514 && ip.src == 192.168.3.100 && !icmp
伺服器(192.168.3.102): Start-pSyslog -Port 514
中繼(192.168.3.99): Start-UDPRelay -inPort 515 -outIP 192.168.3.102 -outPort 514
客戶端(192.168.3.100): Send-pSyslog -Server 192.168.3.99 -PortServer 515 -Content $(Get-Date)
將日誌檔案輸出到物件以收集指標
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
或透過通配符檔名查看舊日誌:
Show-pSyslog -LogFile 05-06 | Out-GridView
範例日誌檔案系統重新啟動: 06-06-2023_reboot.log
日誌檔案輪換並顯示 24 小時內的所有日誌檔案:
Start-pSyslog -RotationSize 500
Show-pSyslog -Count
Show-pSyslog -Count -LogFile 10-06
本機系統日誌輸出範例(使用 tail):
pSyslog 伺服器輸出到控制台 powershell 的範例: