rrg92 / power-zabbix

Powershell module with lot of cmdlets that implements ZABBIX API, extra and auxiliary cmdlets
4 stars 2 forks source link

Hi! I'm trying to get history #3

Open SCH48 opened 4 years ago

SCH48 commented 4 years ago

Hi! I'm trying to get history

Auth-Zabbix -URL 'http://10.248.10.148/zabbix'

image

$Printer = Get-ZabbixHost -Host 'NPI9233D9'
$Printer | ft hostid, Host, Name

image

$Item = Get-ZabbixItem -id 30441
$Item | ft ItemID, Name, key_

image

Get-ZabbixHistory -history 0 -Hosts $Printer -Items $Item -limit 100

= Empty output :-( But simple code work!

$params.body = @{
        "jsonrpc"= "2.0"
        "method" = "history.get"
        "params"= @{
            "output" = "extend"
            "itemids" = "30441"
            "history" = "0"
            "sortfield" = "clock"
            "sortorder" ="DESC"
            "limit" = 10
         }
        auth = ($result.Content | ConvertFrom-Json).result
        id = 1

} | ConvertTo-Json

$result = Invoke-WebRequest @params
$result = Invoke-WebRequest @params
$result.Content #| ConvertFrom-Json

image

Originally posted by @SCH48 in https://github.com/rrg92/power-zabbix/issues/2#issuecomment-635899091

rrg92 commented 4 years ago

Hey @SCH48, thanks your time!

I will analyze this case soon.

SCH48 commented 4 years ago

Problem in param "history" = "0" and Zabbix Printer Template collecting data into the database as a "numeric float". image

History object types to return. Possible values: 0 - numeric float; 1 - character; 2 - log; 3 - numeric unsigned; 4 - text. Default: 3.

I change in Template "float" to "unsigned" image

Testing 2 printers with different templates but same OID "page count" ....

$PrintersInGroups = Get-ZabbixHost -Groups 'Network Printers' -HostStatus 0
$PrintersInGroups| ft hostid, host

image

$OID = "1.3.6.1.2.1.43.10.2.1.4.1.1"
$ItemsOID = Get-ZabbixItem -Hosts $PrintersInGroups | ?{$_.snmp_oid -contains $OID}
$ItemsOID | ft hostid, itemid, snmp_oid, name, lastclock, lastvalue

image

First, testing the correct "itemid=30461"

Get-ZabbixHistory -limit 5 -Items "30461" | ft

image

Default "history" is 3 - "numeric unsigned", All right.

Now check the problem data - "itemid=30441"

Get-ZabbixHistory -limit 5 -Items "30441" | ft

image

Oh, great! But One record? Check "numeric float" data add "-hystory 0":

Get-ZabbixHistory -limit 5 -Items "30441" -history 0 | ft

image

Nothing changed :-(

Test Simple code:

  1. Without "history"
$params.body = @{
        "jsonrpc"= "2.0"
        "method" = "history.get"
        "params"= @{
            "output" = "extend"
            "itemids" = "30441"
            "sortfield" = "clock"
            "sortorder" ="DESC"
            "limit" = 10
         }
        auth = ($result.Content | ConvertFrom-Json).result
        id = 1
} | ConvertTo-Json
$result = (Invoke-WebRequest @params).Content | ConvertFrom-Json
$result.result | ft

image

Also one record. It's the record I translated in "numeric unsigned". But the rest of the entries remained in the "numeric float". Check

  1. Add "history" = 0
$params.body = @{
        "jsonrpc"= "2.0"
        "method" = "history.get"
        "params"= @{
            "output" = "extend"
            "history" = "0"
            "itemids" = "30441"
            "sortfield" = "clock"
            "sortorder" ="DESC"
            "limit" = 10
         }
        auth = ($result.Content | ConvertFrom-Json).result
        id = 1
} | ConvertTo-Json

image

Yes they exist!!!

I understand that I need to convert all the data to one format. But Why does not it work Get-ZabbixHistory -history 0 ?

And is it possible to convert data in the "Get-Zabbix History" command without use the "history" parameter? Ore least a number format lead one to another?

Sorry for my English, I'm Russian. Regards, @SCH48

rrg92 commented 2 years ago

Hi @SCH48 , sorry the delay. I will review this soon.

rrg92 commented 1 month ago

Thank you very much for your analysis efforts. Once again, apologies for the years-long delay. I will investigate what you have put together and see if it still makes sense for corrections