Hello everyone,
I'm new to Zabbix and seeking assistance in understanding how Trapper items work. As I understand it, a Trapper item allows the acceptance of incoming data. This means that it's not the item itself actively querying the server, but rather the server sends data to the item arbitrarily. Typically, this is achieved using a script, such as PowerShell, especially when dealing with a Windows server. To send data to the item, the 'zabbix_sender' command is used, like this: 'zabbix_sender -z <Zabbix server IP address> -p <Zabbix server port> -s "Host name" -k key -o "data value."
Now here's the PowerShell script :
And here's the output :
Now, I want to send this data to the items, so I'm using this command:
However I'm encountering an error :
I think I may have missed something. If someone could show me the way, I would greatly appreciate it.
This is not my doing; I took over NET-CRY's work. Here is his GitHub.
I'm sorry for my approximate English.
I'm new to Zabbix and seeking assistance in understanding how Trapper items work. As I understand it, a Trapper item allows the acceptance of incoming data. This means that it's not the item itself actively querying the server, but rather the server sends data to the item arbitrarily. Typically, this is achieved using a script, such as PowerShell, especially when dealing with a Windows server. To send data to the item, the 'zabbix_sender' command is used, like this: 'zabbix_sender -z <Zabbix server IP address> -p <Zabbix server port> -s "Host name" -k key -o "data value."
Now here's the PowerShell script :
Code:
$input_path = "C:\Program Files\Zabbix Agent\Script\Winbackup.ps1"
$regex = "^Hostname=[\s+]*(.*)"
$matches = Select-String -Path $input_path -Pattern $regex -AllMatches
$currentDateTime = Get-Date
$ts = New-TimeSpan -Hours 24
if ($matches) {
$hostname = $matches.Matches.Groups[1].Value
} else {
$hostname = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
}
$lastBackup = $null
$backupdata = Get-WBJob -previous 1
if ($backupdata.JobType -eq "Backup") {
$starttime = $backupdata.startTime
$start_datetime = [datetime]::ParseExact($starttime, 'dd/MM/yyyy HH:mm', $null)
$timeSinceLastBackup = $currentDateTime - $start_datetime
if ($timeSinceLastBackup -gt $ts) {
$errorcode = 2
}
}
#Afficher la date et l'heure de la dernière sauvegarde
Write-Host "$hostname wb.lastbackup $($start_datetime.ToString('dd/MM/yyyy HH:mm'))"
$ts = New-TimeSpan -Days 1 -Hours 12 -Minutes 30
$expired = (Get-Date) - $ts
$backupdata_array = Get-WBJob -previous 10
foreach ($backupdata in $backupdata_array) {
$JobType = $backupdata.JobType
if ($JobType -eq "Backup") {
$starttime = $backupdata.startTime
$endtime = $backupdata.endTime
$errormsg = $backupdata.errorDescription
$originalerrormsg = $backupdata.errorDescription
$resultcode = $backupdata.HResult
$JobType = $backupdata.JobType
if ($errormsg.Length -eq 0) {
$endtime_datetime = [datetime]::ParseExact($endtime, 'dd/MM/yyyy HH:mm', $null)
$start_datetime = [datetime]::ParseExact($starttime, 'dd/MM/yyyy HH:mm', $null)
$duration = ($endtime_datetime - $start_datetime).TotalMinutes
break
}
}
}
$endtime = [datetime]::ParseExact($endtime, 'dd/MM/yyyy HH:mm', $null)
$DateTime = (Get-Date).ToUniversalTime()
$UnixTimeStamp = [System.Math]::Truncate((Get-Date -Date $DateTime -UFormat %s))
if ($errormsg.Length -eq 0) {
$errorcode = 0;
$errormsg = "-";
} else {
$errorcode = 1;
}
Write-Host "$hostname wb.errorcode $errorcode"
Write-Host "$hostname wb.resultcode $resultcode"
Write-Host "$hostname wb.duration $duration min"
Write-Host "$hostname wb.errormsg $errormsg"
Write-Host "$hostname wb.starttime $starttime"
Write-Host "$hostname wb.timestamp $UnixTimeStamp"
Code:
hostname wb.lastbackup value hostname wb.errorcode vlaue hostname wb.resultcode value hostname wb.duration value hostname wb.errormsg value hostname wb.starttime value hostname wb.timestamp value
Code:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" -File "C:\Program Files\Zabbix Agent\Script\Winbackup.ps1" | "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -c "C:\Program Files\Zabbix Agent\zabbix_agentd.conf" -i - -vv
Code:
zabbix_sender.exe [7140]: ERROR: [line 3] 'Key' required Sending failed
This is not my doing; I took over NET-CRY's work. Here is his GitHub.
I'm sorry for my approximate English.
Comment