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 20 #ifndef ZABBIX_ZBXTASKS_H 21 #define ZABBIX_ZBXTASKS_H 22 23 #include "zbxalgo.h" 24 #include "zbxjson.h" 25 26 #define ZBX_TASK_UPDATE_FREQUENCY 1 27 28 #define ZBX_REMOTE_COMMAND_TTL (SEC_PER_MIN * 10) 29 30 /* task manager task types */ 31 #define ZBX_TM_TASK_UNDEFINED 0 32 #define ZBX_TM_TASK_CLOSE_PROBLEM 1 33 #define ZBX_TM_TASK_REMOTE_COMMAND 2 34 #define ZBX_TM_TASK_REMOTE_COMMAND_RESULT 3 35 #define ZBX_TM_TASK_ACKNOWLEDGE 4 36 #define ZBX_TM_TASK_UPDATE_EVENTNAMES 5 37 #define ZBX_TM_TASK_CHECK_NOW 6 38 39 /* task manager task states */ 40 #define ZBX_TM_STATUS_NEW 1 41 #define ZBX_TM_STATUS_INPROGRESS 2 42 #define ZBX_TM_STATUS_DONE 3 43 #define ZBX_TM_STATUS_EXPIRED 4 44 45 /* the time period after which finished (done/expired) tasks are removed */ 46 #define ZBX_TM_CLEANUP_TASK_AGE SEC_PER_DAY 47 48 typedef struct 49 { 50 int command_type; 51 char *command; 52 int execute_on; 53 int port; 54 int authtype; 55 char *username; 56 char *password; 57 char *publickey; 58 char *privatekey; 59 zbx_uint64_t parent_taskid; 60 zbx_uint64_t hostid; 61 zbx_uint64_t alertid; 62 } 63 zbx_tm_remote_command_t; 64 65 typedef struct 66 { 67 int status; 68 char *info; 69 zbx_uint64_t parent_taskid; 70 } 71 zbx_tm_remote_command_result_t; 72 73 typedef struct 74 { 75 zbx_uint64_t itemid; 76 } 77 zbx_tm_check_now_t; 78 79 typedef struct 80 { 81 /* the task identifier */ 82 zbx_uint64_t taskid; 83 /* the target proxy hostid or 0 if the task must be on server, ignored by proxy */ 84 zbx_uint64_t proxy_hostid; 85 /* the task type (ZBX_TM_TASK_* defines) */ 86 unsigned char type; 87 /* the task status (ZBX_TM_STATUS_* defines) */ 88 unsigned char status; 89 /* the task creation time */ 90 int clock; 91 /* the task expiration period in seconds */ 92 int ttl; 93 94 /* the task data, depending on task type */ 95 void *data; 96 } 97 zbx_tm_task_t; 98 99 100 zbx_tm_task_t *zbx_tm_task_create(zbx_uint64_t taskid, unsigned char type, unsigned char status, int clock, int ttl, 101 zbx_uint64_t proxy_hostid); 102 void zbx_tm_task_clear(zbx_tm_task_t *task); 103 void zbx_tm_task_free(zbx_tm_task_t *task); 104 105 zbx_tm_remote_command_t *zbx_tm_remote_command_create(int command_type, const char *command, int execute_on, int port, 106 int authtype, const char *username, const char *password, const char *publickey, const char *privatekey, 107 zbx_uint64_t parent_taskid, zbx_uint64_t hostid, zbx_uint64_t alertid); 108 109 zbx_tm_remote_command_result_t *zbx_tm_remote_command_result_create(zbx_uint64_t parent_taskid, int status, 110 const char *info); 111 112 zbx_tm_check_now_t *zbx_tm_check_now_create(zbx_uint64_t itemid); 113 114 void zbx_tm_save_tasks(zbx_vector_ptr_t *tasks); 115 int zbx_tm_save_task(zbx_tm_task_t *task); 116 117 void zbx_tm_get_proxy_tasks(zbx_vector_ptr_t *tasks, zbx_uint64_t proxy_hostid); 118 void zbx_tm_update_task_status(zbx_vector_ptr_t *tasks, int status); 119 void zbx_tm_json_serialize_tasks(struct zbx_json *json, const zbx_vector_ptr_t *tasks); 120 void zbx_tm_json_deserialize_tasks(const struct zbx_json_parse *jp, zbx_vector_ptr_t *tasks); 121 122 /* separate implementation for proxy and server */ 123 void zbx_tm_get_remote_tasks(zbx_vector_ptr_t *tasks, zbx_uint64_t proxy_hostid); 124 125 #endif 126