Esempio n. 1
0
/******************************************************************************
 *                                                                            *
 * Function:                                                                  *
 *                                                                            *
 * Purpose:                                                                   *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int jarun_icon_info(const zbx_uint64_t inner_job_id)
{
    DB_RESULT result;
    DB_ROW row;
    int status;
    char str_status[4];
    zbx_uint64_t inner_jobnet_id;
    int info_flag;
    char *get_job_id, *get_calendar_id;
    const char *__function_name = "jarun_icon_info";

    zabbix_log(LOG_LEVEL_DEBUG, "In %s() inner_job_id: " ZBX_FS_UI64,
               __function_name, inner_job_id);

    result =
        DBselect
        ("select inner_jobnet_id, info_flag, get_job_id, get_calendar_id"
         " from ja_run_icon_info_table" " where inner_job_id = "
         ZBX_FS_UI64, inner_job_id);

    status = -1;
    if (NULL != (row = DBfetch(result))) {
        ZBX_STR2UINT64(inner_jobnet_id, row[0]);
        info_flag = atoi(row[1]);
        get_job_id = row[2];
        get_calendar_id = row[3];
        switch (info_flag) {
        case 0:
            status = jarun_icon_info_get_status(inner_jobnet_id, get_job_id, inner_job_id);
            break;
        case 3:
            status = jarun_icon_info_get_calendar(get_calendar_id, inner_job_id);
            break;
        default:
            break;
        }
    } else {
        ja_log("JARUNICONINFO200003", inner_jobnet_id, NULL, inner_job_id,
               __function_name, inner_job_id);
        DBfree_result(result);
        return FAIL;
    }
    DBfree_result(result);
    if (status < 0)
        return ja_set_runerr(inner_job_id, 2);

    zbx_snprintf(str_status, sizeof(str_status), "%d", status);
    ja_set_value_after(inner_job_id, inner_jobnet_id, "LAST_STATUS",
                       str_status);

    return ja_flow(inner_job_id, JA_FLOW_TYPE_NORMAL, 1);
}
Esempio n. 2
0
/******************************************************************************
 *                                                                            *
 * Function:                                                                  *
 *                                                                            *
 * Purpose:                                                                   *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int jarun_icon_extjob_run(const zbx_uint64_t inner_job_id,
                          const zbx_uint64_t inner_jobnet_id,
                          const char *command)
{
    int ret, db_ret;
    pid_t pid;
    char filepath[JA_MAX_STRING_LEN];
    char full_command[JA_MAX_STRING_LEN];
    char jacmd[JA_MAX_STRING_LEN];
    const char *__function_name = "jarun_icon_extjob_run";

    zabbix_log(LOG_LEVEL_DEBUG,
               "In %s() inner_job_id: " ZBX_FS_UI64
               ", command: %s", __function_name, inner_job_id, command);

    ret = SUCCEED;
    zbx_snprintf(filepath, JA_MAX_STRING_LEN, "%s%c%s-" ZBX_FS_UI64,
                 CONFIG_TMPDIR, JA_DLM, progname, inner_job_id);
    zbx_snprintf(full_command, JA_MAX_STRING_LEN, "%s.%s", filepath,
                 JA_EXE);
    zbx_snprintf(jacmd, JA_MAX_STRING_LEN, "%s%c%s", CONFIG_EXTJOB_PATH,
                 JA_DLM, JA_JOBARG_COMMAND);
    if (ja_jobfile_create(filepath, jobext, command) != SUCCEED) {
        return ja_set_runerr(inner_job_id);
    }

    pid = ja_fork();
    if (pid == -1) {
        ja_log("JARUNICONEXTJOB200001", inner_jobnet_id, NULL,
               inner_job_id, __function_name);
        return ja_set_runerr(inner_job_id);
    } else if (pid != 0) {
        waitpid(pid, NULL, WNOHANG);
        db_ret =
            DBexecute
            ("update ja_run_icon_extjob_table set pid = %d where inner_job_id = "
             ZBX_FS_UI64, pid, inner_job_id);
        if (db_ret < ZBX_DB_OK) {
            ja_log("JARUNICONEXTJOB200006", inner_jobnet_id, NULL,
                   inner_job_id, __function_name, pid, inner_job_id);
            return FAIL;
        }
        zabbix_log(LOG_LEVEL_DEBUG,
                   "End of %s() inner_job_id: " ZBX_FS_UI64,
                   __function_name, inner_job_id);
        return SUCCEED;
    }

    DBconnect(ZBX_DB_CONNECT_ONCE);
    if (ja_setenv(inner_job_id) == FAIL) {
        DBclose();
        goto error;
    }
    DBclose();
    execl(jacmd, JA_JOBARG_COMMAND, filepath, full_command, NULL);

  error:
    DBconnect(ZBX_DB_CONNECT_ONCE);
    ja_log("JARUNICONEXTJOB200003", inner_jobnet_id, NULL, inner_job_id,
           __function_name, jacmd, zbx_strerror(errno));
    ja_set_runerr(inner_job_id);
    DBclose();
    exit(0);
}
Esempio n. 3
0
/******************************************************************************
 *                                                                            *
 * Function:                                                                  *
 *                                                                            *
 * Purpose:                                                                   *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int jarun_icon_extjob(const zbx_uint64_t inner_job_id, const int test_flag)
{
    int ret;
    DB_RESULT result;
    DB_ROW row;
    zbx_uint64_t inner_jobnet_id, inner_jobnet_main_id;
    char command_id[JA_MAX_STRING_LEN], value[JA_MAX_STRING_LEN],
        start_time[16], command[JA_MAX_DATA_LEN];
    const char *__function_name = "jarun_icon_extjob";

    zabbix_log(LOG_LEVEL_DEBUG, "In %s() inner_job_id: " ZBX_FS_UI64,
               __function_name, inner_job_id);

    result =
        DBselect
        ("select inner_jobnet_id, command_id, value from ja_run_icon_extjob_table"
         " where inner_job_id = " ZBX_FS_UI64, inner_job_id);
    row = DBfetch(result);
    if (row == NULL) {
        ja_log("JARUNICONEXTJOB200004", 0, NULL, inner_job_id,
               __function_name, inner_job_id);
        DBfree_result(result);
        return ja_set_runerr(inner_job_id);
    }

    ZBX_STR2UINT64(inner_jobnet_id, row[0]);
    zbx_snprintf(command_id, sizeof(command_id), "%s", row[1]);
    ja_format_extjob(row[2], value);
    DBfree_result(result);

    result =
        DBselect
        ("select inner_jobnet_main_id from ja_run_jobnet_table"
         " where inner_jobnet_id = " ZBX_FS_UI64, inner_jobnet_id);
    row = DBfetch(result);
    if (row == NULL) {
        ja_log("JARUNICONEXTJOB200007", 0, NULL, inner_job_id,
               __function_name, inner_jobnet_id);
        DBfree_result(result);
        return ja_set_runerr(inner_job_id);
    }
    ZBX_STR2UINT64(inner_jobnet_main_id, row[0]);
    DBfree_result(result);

    if (test_flag == JA_JOB_TEST_FLAG_ON) {
        zbx_snprintf(command, sizeof(command), " ");
    } else {
        if (strcmp(command_id, JA_CMD_TIME) == 0) {
            if (ja_get_jobnet_summary_start(inner_jobnet_main_id, start_time) ==
                FAIL) {
                ja_log("JARUNICONEXTJOB200005", inner_jobnet_main_id, NULL,
                       inner_job_id, __function_name, inner_jobnet_main_id);
                return ja_set_runerr(inner_job_id);
            }
            zbx_snprintf(command, sizeof(command), "%s%c%s %s %s",
                         CONFIG_EXTJOB_PATH, JA_DLM, command_id, value,
                         start_time);
        } else {
            zbx_snprintf(command, sizeof(command), "%s%c%s %s",
                         CONFIG_EXTJOB_PATH, JA_DLM, command_id, value);
        }
    }
    ret = jarun_icon_extjob_run(inner_job_id, inner_jobnet_id, command);

    zabbix_log(LOG_LEVEL_DEBUG, "End of %s() inner_job_id: " ZBX_FS_UI64,
               __function_name, inner_job_id);
    return ret;
}