All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zabbix4j.webscenario.WebScenario Maven / Gradle / Ivy

The newest version!
package com.zabbix4j.webscenario;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.ZabbixApiMethod;

/**
 * @author Suguru Yajima
 */
public class WebScenario extends ZabbixApiMethod {

    public WebScenario(String apiUrl, String auth) {
        super(apiUrl, auth);
    }

    public HttpTestCreateResponse create(HttpTestCreateRequest request) throws ZabbixApiException {
        HttpTestCreateResponse response = null;
        request.setAuth(auth);

        Gson gson = new GsonBuilder().setPrettyPrinting().create();

        String requestJson = gson.toJson(request);

        try {
            String responseJson = sendRequest(requestJson);

            response = gson.fromJson(responseJson, HttpTestCreateResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }

    public HttpTestDeleteResponse delete(HttpTestDeleteRequest request) throws ZabbixApiException {
        HttpTestDeleteResponse response = null;
        request.setAuth(auth);

        Gson gson = new GsonBuilder().setPrettyPrinting().create();

        String requestJson = gson.toJson(request);

        try {
            String responseJson = sendRequest(requestJson);

            response = gson.fromJson(responseJson, HttpTestDeleteResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }

    public HttpTestUpdateRespose update(HttpTestUpdateRequest request) throws ZabbixApiException {
        HttpTestUpdateRespose response = null;
        request.setAuth(auth);

        Gson gson = new GsonBuilder().setPrettyPrinting().create();

        String requestJson = gson.toJson(request);

        try {
            String responseJson = sendRequest(requestJson);

            response = gson.fromJson(responseJson, HttpTestUpdateRespose.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }

    public HttpTestGetResponse get(HttpTestGetRequest request) throws ZabbixApiException {
        HttpTestGetResponse response = null;
        request.setAuth(auth);

        Gson gson = new GsonBuilder().setPrettyPrinting().create();

        String requestJson = gson.toJson(request);

        try {
            String responseJson = sendRequest(requestJson);

            response = gson.fromJson(responseJson, HttpTestGetResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy