zabbix-tools / go-zabbix

Go bindings for the Zabbix API
GNU General Public License v2.0
106 stars 70 forks source link

Adding History API #24

Closed sconwayubb closed 5 years ago

sconwayubb commented 5 years ago

I haven't been able to test the Event Log History, since we don't use those in our environment. Also, the history.get endpoint doesn't return the ValueType like item.get does, so I left it as a string.

Usage:

sevenDaysAgo := time.Now().AddDate(0, 0, -7)

for _, i := range items {
    histories, err := api.GetHistories(zabbix.HistoryGetParams{
        ItemIDs:  []string{strconv.Itoa(i.ItemID)},
        TimeFrom: float64(sevenDaysAgo.Unix())})
    if len(histories) == 0 {
        fmt.Printf("%s - No history found\n", i.ItemName)
        continue
    }
        // do stuff with histories
}
cavaliercoder commented 5 years ago

Thanks for this!