Ad Widget

Collapse

Monitoring Windows Backup

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bl4nk
    Junior Member
    • Oct 2023
    • 2

    #1

    Monitoring Windows Backup

    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 :

    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"
    
    ​
    And here's the output :

    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
    Now, I want to send this data to the items, so I'm using this command:

    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
    However I'm encountering an error :

    Code:
    zabbix_sender.exe [7140]: ERROR: [line 3] 'Key' required
    Sending failed
    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.


  • Bl4nk
    Junior Member
    • Oct 2023
    • 2

    #2
    "Here is NET-CRY's GitHub. I apologize for forgetting to include it in my previous post.
    zabbix monitoring. Contribute to NET-CRY/zabbix development by creating an account on GitHub.



    Then, I used the command 'zabbix_sender -z <Zabbix server IP address> -p <Zabbix server port> -s "Host name" -k key -o "data value."' to understand the error from the previous command, and I encountered an issue. My Zabbix server's configuration listens on port 10050 and all IP addresses, but I received the error
    zabbix_sender [14064]: Warning: incorrect answer from "Zabbix server's IP": []'
    Code:
    zabbix_sender -z zabbixIP -p 10050 -s hostname -k wb.starttime -o "30/10/2023 02:15" -vv

    Comment

    Working...