1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
#ifndef ZABBIX_ZBXTASKS_H
#define ZABBIX_ZBXTASKS_H
#include "zbxalgo.h"
#include "zbxjson.h"
#include "zbxversion.h"
#define ZBX_TASK_UPDATE_FREQUENCY 1
#define ZBX_REMOTE_COMMAND_TTL (SEC_PER_MIN * 10)
#define ZBX_DATA_TTL 30
#define ZBX_DATA_ACTIVE_PROXY_CONFIG_RELOAD_TTL (SEC_PER_MIN * 10)
/* task manager task types */
#define ZBX_TM_TASK_UNDEFINED 0
#define ZBX_TM_TASK_CLOSE_PROBLEM 1
#define ZBX_TM_TASK_REMOTE_COMMAND 2
#define ZBX_TM_TASK_REMOTE_COMMAND_RESULT 3
#define ZBX_TM_TASK_ACKNOWLEDGE 4
#define ZBX_TM_TASK_UPDATE_EVENTNAMES 5
#define ZBX_TM_TASK_CHECK_NOW 6
#define ZBX_TM_TASK_DATA 7
#define ZBX_TM_TASK_DATA_RESULT 8
#define ZBX_TM_PROXYDATA 9
/* task manager task states */
#define ZBX_TM_STATUS_NEW 1
#define ZBX_TM_STATUS_INPROGRESS 2
#define ZBX_TM_STATUS_DONE 3
#define ZBX_TM_STATUS_EXPIRED 4
/* task data type */
#define ZBX_TM_DATA_TYPE_TEST_ITEM 0
#define ZBX_TM_DATA_TYPE_DIAGINFO 1
#define ZBX_TM_DATA_TYPE_PROXYIDS 2
#define ZBX_TM_DATA_TYPE_PROXYNAME 3
#define ZBX_TM_DATA_TYPE_ACTIVE_PROXY_CONFIG_RELOAD 4
#define ZBX_TM_DATA_TYPE_TEMP_SUPPRESSION 5
#define ZBX_TM_DATA_TYPE_RANK_EVENT 6
/* the time period after which finished (done/expired) tasks are removed */
#define ZBX_TM_CLEANUP_TASK_AGE SEC_PER_DAY
typedef struct
{
int command_type;
char *command;
int execute_on;
int port;
int authtype;
char *username;
char *password;
char *publickey;
char *privatekey;
zbx_uint64_t parent_taskid;
zbx_uint64_t hostid;
zbx_uint64_t alertid;
}
zbx_tm_remote_command_t;
typedef struct
{
int status;
char *info;
zbx_uint64_t parent_taskid;
}
zbx_tm_remote_command_result_t;
typedef struct
{
zbx_uint64_t itemid;
}
zbx_tm_check_now_t;
typedef struct
{
zbx_uint64_t parent_taskid;
char *data;
int type;
}
zbx_tm_data_t;
typedef struct
{
int status;
char *info;
zbx_uint64_t parent_taskid;
}
zbx_tm_data_result_t;
typedef struct
{
/* the task identifier */
zbx_uint64_t taskid;
/* the target proxy hostid or 0 if the task must be on server, ignored by proxy */
zbx_uint64_t proxyid;
/* the task type (ZBX_TM_TASK_* defines) */
unsigned char type;
/* the task status (ZBX_TM_STATUS_* defines) */
unsigned char status;
/* the task creation time */
int clock;
/* the task expiration period in seconds */
int ttl;
/* the task data, depending on task type */
void *data;
}
zbx_tm_task_t;
ZBX_PTR_VECTOR_DECL(tm_task, zbx_tm_task_t *)
void zbx_tm_task_free(zbx_tm_task_t *task);
zbx_tm_remote_command_t *zbx_tm_remote_command_create(int command_type, const char *command, int execute_on, int port,
int authtype, const char *username, const char *password, const char *publickey, const char *privatekey,
zbx_uint64_t parent_taskid, zbx_uint64_t hostid, zbx_uint64_t alertid);
zbx_tm_remote_command_result_t *zbx_tm_remote_command_result_create(zbx_uint64_t parent_taskid, int status,
const char *info);
zbx_tm_check_now_t *zbx_tm_check_now_create(zbx_uint64_t itemid);
zbx_tm_data_t *zbx_tm_data_create(zbx_uint64_t parent_taskid, const char *str, size_t len, int type);
zbx_tm_data_result_t *zbx_tm_data_result_create(zbx_uint64_t parent_taskid, int status, const char *info);
zbx_tm_task_t *zbx_tm_task_create(zbx_uint64_t taskid, unsigned char type, unsigned char status, int clock, int ttl,
zbx_uint64_t proxyid);
void zbx_tm_save_tasks(zbx_vector_tm_task_t *tasks);
int zbx_tm_save_task(zbx_tm_task_t *task);
void zbx_tm_update_task_status(zbx_vector_tm_task_t *tasks, int status);
void zbx_tm_json_serialize_tasks(struct zbx_json *json, const zbx_vector_tm_task_t *tasks);
void zbx_tm_json_deserialize_tasks(const struct zbx_json_parse *jp, zbx_vector_tm_task_t *tasks);
int zbx_tm_execute_task_data(const char *data, size_t len, zbx_uint64_t proxyid, char **info);
#endif
|