Skip to content

Commit 905426f

Browse files
committed
Fix unmarshal err
1 parent 88216af commit 905426f

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

examples/script_example.png

1.67 KB
Loading

src/zabbix.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ type Hosts struct {
1414
}
1515

1616
type Result struct {
17-
Hostid string `json:"hostid"`
17+
Hostid string `json:"hostid,omitempty"`
18+
Maintenanceids []string `json:"maintenanceids,omitempty"`
19+
}
20+
21+
type Maintenance struct {
22+
Result Result `json:"result"`
23+
Error Error `json:"error"`
1824
}
1925

2026
type Error struct {
@@ -42,7 +48,6 @@ func getHostID(cfg Config, hostname string) (string, error) {
4248
if err = json.Unmarshal(body, &host); err != nil {
4349
return "", err
4450
}
45-
4651
return host.Results[0].Hostid, nil
4752
}
4853

@@ -73,7 +78,8 @@ func scheduleMaintenance(cfg Config, currentTime, maintenanceTime int64, hostID,
7378
if err != nil {
7479
return fmt.Errorf("failed to create maintenance: %s", err.Error())
7580
}
76-
var res Hosts
81+
82+
var res Maintenance
7783
if err = json.Unmarshal(body, &res); err != nil {
7884
return err
7985
}

0 commit comments

Comments
 (0)