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

com.zabbix4j.script.Script Maven / Gradle / Ivy

There is a newer version: 0.1.9
Show newest version
package com.zabbix4j.script;

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

/**
 * @author Suguru Yajima
 */
public class Script extends ZabbixApiMethod {
    public Script(String apiUrl, String auth) {
        super(apiUrl, auth);
    }

    public ScriptCreateResponse create(ScriptCreateRequest request) throws ZabbixApiException {
        ScriptCreateResponse 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, ScriptCreateResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }

    public ScriptDeleteResponse delete(ScriptDeleteRequest request) throws ZabbixApiException {
        ScriptDeleteResponse 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, ScriptDeleteResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }

    public ScriptUpdateResponse update(ScriptUpdateRequest request) throws ZabbixApiException {
        ScriptUpdateResponse 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, ScriptUpdateResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }

    public ScriptGetResponse get(ScriptGetRequest request) throws ZabbixApiException {
        ScriptGetResponse 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, ScriptGetResponse.class);
        } catch (ZabbixApiException e) {
            throw new ZabbixApiException(e);
        }

        return response;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy