1/*
2** Zabbix
3** Copyright (C) 2001-2021 Zabbix SIA
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18**/
19
20package zbxlib
21
22/*
23#cgo CFLAGS: -I${SRCDIR}/../../../../include
24
25#include "common.h"
26
27int	zbx_get_agent_item_nextcheck(zbx_uint64_t itemid, const char *delay, unsigned char state, int now,
28		int refresh_unsupported, int *nextcheck, char **error);
29*/
30import "C"
31
32import (
33	"errors"
34	"time"
35	"unsafe"
36)
37
38func GetNextcheck(itemid uint64, delay string, from time.Time, unsupported bool, refresh_unsupported int) (nextcheck time.Time, err error) {
39	var cnextcheck C.int
40	var cerr *C.char
41	var state int
42	cdelay := C.CString(delay)
43
44	if unsupported {
45		state = ItemStateNotsupported
46	} else {
47		state = ItemStateNormal
48	}
49	now := from.Unix()
50	ret := C.zbx_get_agent_item_nextcheck(C.zbx_uint64_t(itemid), cdelay, C.uchar(state), C.int(now),
51		C.int(refresh_unsupported), &cnextcheck, &cerr)
52
53	if ret != Succeed {
54		err = errors.New(C.GoString(cerr))
55		C.free(unsafe.Pointer(cerr))
56	} else {
57		nextcheck = time.Unix(int64(cnextcheck), 0)
58	}
59	C.free(unsafe.Pointer(cdelay))
60
61	return
62}
63