@Test public void testActionCreate() { ServerGroupDO serverGroupDO = new ServerGroupDO(); serverGroupDO.setName("group_sdop"); System.err.println(zabbixServiceImpl.actionCreate(serverGroupDO)); }
@Override public int actionCreate(ServerGroupDO serverGroupDO) { int actionid = actionGet(serverGroupDO); if (actionid != 0) return actionid; String usergrpName = serverGroupDO.getName().replace("group_", "users_"); ZabbixRequest request = ZabbixRequestBuilder.newBuilder() .method("action.create").build(); request.putParam("name", "Report problems to " + usergrpName); request.putParam("eventsource", 0); request.putParam("status", 0); request.putParam("esc_period", 3600); request.putParam("def_shortdata", "{TRIGGER.NAME}: {TRIGGER.STATUS}"); request.putParam("def_longdata", "ServerName:{HOST.NAME} IP:{HOST.IP}\r\nTrigger: {TRIGGER.NAME}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nItem values: {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\nOriginal event ID: {EVENT.ID}"); JSONArray operations = new JSONArray(); JSONObject operation = new JSONObject(); operation.put("operationtype", 0); operation.put("esc_period", 0); operation.put("esc_step_from", 1); operation.put("esc_step_to", 1); operation.put("evaltype", 0); JSONArray opmessage_grp = new JSONArray(); JSONObject usrgrp = new JSONObject(); usrgrp.put("usrgrpid", usergroupGet(usergrpName)); opmessage_grp.add(usrgrp); operation.put("opmessage_grp", opmessage_grp); JSONObject opmessage = new JSONObject(); opmessage.put("mediatypeid", 0); opmessage.put("default_msg", 1); opmessage.put("subject", "{TRIGGER.STATUS}: {TRIGGER.NAME}"); opmessage.put("message", "Trigger: {TRIGGER.NAME}\r\nTrigger status: {TRIGGER.STATUS}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nTrigger URL: {TRIGGER.URL}\r\n\r\nItem values:\r\n\r\n1. {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\n2. {ITEM.NAME2} ({HOST.NAME2}:{ITEM.KEY2}): {ITEM.VALUE2}\r\n3. {ITEM.NAME3} ({HOST.NAME3}:{ITEM.KEY3}): {ITEM.VALUE3}\r\n\r\nOriginal event ID: {EVENT.ID}"); operation.put("opmessage", opmessage); operations.add(operation); request.putParam("operations", operations); JSONObject filter = new JSONObject(); filter.put("evaltype", 1); JSONArray conditions = new JSONArray(); JSONObject conditionA = new JSONObject(); conditionA.put("conditiontype", 16); conditionA.put("operator", 7); conditionA.put("value", ""); conditionA.put("formulaid", "A"); conditions.add(conditionA); JSONObject conditionB = new JSONObject(); conditionB.put("conditiontype", 5); conditionB.put("operator", 0); conditionB.put("value", "1"); conditionB.put("formulaid", "B"); conditions.add(conditionB); JSONObject conditionC = new JSONObject(); conditionC.put("conditiontype", 0); conditionC.put("operator", 1); conditionC.put("value", hostgroupGet("group_gray")); conditionC.put("formulaid", "C"); conditions.add(conditionC); JSONObject conditionD = new JSONObject(); conditionD.put("conditiontype", 0); conditionD.put("operator", 0); conditionD.put("value", hostgroupGet(serverGroupDO.getName())); conditionD.put("formulaid", "D"); conditions.add(conditionD); filter.put("conditions", conditions); request.putParam("filter", filter); JSONObject getResponse = call(request); return getResultId(getResponse, "actionids"); }
ZabbixServiceImpl implements ZabbixService, InitializingBean { @Override public int actionCreate(ServerGroupDO serverGroupDO) { int actionid = actionGet(serverGroupDO); if (actionid != 0) return actionid; String usergrpName = serverGroupDO.getName().replace("group_", "users_"); ZabbixRequest request = ZabbixRequestBuilder.newBuilder() .method("action.create").build(); request.putParam("name", "Report problems to " + usergrpName); request.putParam("eventsource", 0); request.putParam("status", 0); request.putParam("esc_period", 3600); request.putParam("def_shortdata", "{TRIGGER.NAME}: {TRIGGER.STATUS}"); request.putParam("def_longdata", "ServerName:{HOST.NAME} IP:{HOST.IP}\r\nTrigger: {TRIGGER.NAME}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nItem values: {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\nOriginal event ID: {EVENT.ID}"); JSONArray operations = new JSONArray(); JSONObject operation = new JSONObject(); operation.put("operationtype", 0); operation.put("esc_period", 0); operation.put("esc_step_from", 1); operation.put("esc_step_to", 1); operation.put("evaltype", 0); JSONArray opmessage_grp = new JSONArray(); JSONObject usrgrp = new JSONObject(); usrgrp.put("usrgrpid", usergroupGet(usergrpName)); opmessage_grp.add(usrgrp); operation.put("opmessage_grp", opmessage_grp); JSONObject opmessage = new JSONObject(); opmessage.put("mediatypeid", 0); opmessage.put("default_msg", 1); opmessage.put("subject", "{TRIGGER.STATUS}: {TRIGGER.NAME}"); opmessage.put("message", "Trigger: {TRIGGER.NAME}\r\nTrigger status: {TRIGGER.STATUS}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nTrigger URL: {TRIGGER.URL}\r\n\r\nItem values:\r\n\r\n1. {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\n2. {ITEM.NAME2} ({HOST.NAME2}:{ITEM.KEY2}): {ITEM.VALUE2}\r\n3. {ITEM.NAME3} ({HOST.NAME3}:{ITEM.KEY3}): {ITEM.VALUE3}\r\n\r\nOriginal event ID: {EVENT.ID}"); operation.put("opmessage", opmessage); operations.add(operation); request.putParam("operations", operations); JSONObject filter = new JSONObject(); filter.put("evaltype", 1); JSONArray conditions = new JSONArray(); JSONObject conditionA = new JSONObject(); conditionA.put("conditiontype", 16); conditionA.put("operator", 7); conditionA.put("value", ""); conditionA.put("formulaid", "A"); conditions.add(conditionA); JSONObject conditionB = new JSONObject(); conditionB.put("conditiontype", 5); conditionB.put("operator", 0); conditionB.put("value", "1"); conditionB.put("formulaid", "B"); conditions.add(conditionB); JSONObject conditionC = new JSONObject(); conditionC.put("conditiontype", 0); conditionC.put("operator", 1); conditionC.put("value", hostgroupGet("group_gray")); conditionC.put("formulaid", "C"); conditions.add(conditionC); JSONObject conditionD = new JSONObject(); conditionD.put("conditiontype", 0); conditionD.put("operator", 0); conditionD.put("value", hostgroupGet(serverGroupDO.getName())); conditionD.put("formulaid", "D"); conditions.add(conditionD); filter.put("conditions", conditions); request.putParam("filter", filter); JSONObject getResponse = call(request); return getResultId(getResponse, "actionids"); } }
ZabbixServiceImpl implements ZabbixService, InitializingBean { @Override public int actionCreate(ServerGroupDO serverGroupDO) { int actionid = actionGet(serverGroupDO); if (actionid != 0) return actionid; String usergrpName = serverGroupDO.getName().replace("group_", "users_"); ZabbixRequest request = ZabbixRequestBuilder.newBuilder() .method("action.create").build(); request.putParam("name", "Report problems to " + usergrpName); request.putParam("eventsource", 0); request.putParam("status", 0); request.putParam("esc_period", 3600); request.putParam("def_shortdata", "{TRIGGER.NAME}: {TRIGGER.STATUS}"); request.putParam("def_longdata", "ServerName:{HOST.NAME} IP:{HOST.IP}\r\nTrigger: {TRIGGER.NAME}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nItem values: {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\nOriginal event ID: {EVENT.ID}"); JSONArray operations = new JSONArray(); JSONObject operation = new JSONObject(); operation.put("operationtype", 0); operation.put("esc_period", 0); operation.put("esc_step_from", 1); operation.put("esc_step_to", 1); operation.put("evaltype", 0); JSONArray opmessage_grp = new JSONArray(); JSONObject usrgrp = new JSONObject(); usrgrp.put("usrgrpid", usergroupGet(usergrpName)); opmessage_grp.add(usrgrp); operation.put("opmessage_grp", opmessage_grp); JSONObject opmessage = new JSONObject(); opmessage.put("mediatypeid", 0); opmessage.put("default_msg", 1); opmessage.put("subject", "{TRIGGER.STATUS}: {TRIGGER.NAME}"); opmessage.put("message", "Trigger: {TRIGGER.NAME}\r\nTrigger status: {TRIGGER.STATUS}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nTrigger URL: {TRIGGER.URL}\r\n\r\nItem values:\r\n\r\n1. {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\n2. {ITEM.NAME2} ({HOST.NAME2}:{ITEM.KEY2}): {ITEM.VALUE2}\r\n3. {ITEM.NAME3} ({HOST.NAME3}:{ITEM.KEY3}): {ITEM.VALUE3}\r\n\r\nOriginal event ID: {EVENT.ID}"); operation.put("opmessage", opmessage); operations.add(operation); request.putParam("operations", operations); JSONObject filter = new JSONObject(); filter.put("evaltype", 1); JSONArray conditions = new JSONArray(); JSONObject conditionA = new JSONObject(); conditionA.put("conditiontype", 16); conditionA.put("operator", 7); conditionA.put("value", ""); conditionA.put("formulaid", "A"); conditions.add(conditionA); JSONObject conditionB = new JSONObject(); conditionB.put("conditiontype", 5); conditionB.put("operator", 0); conditionB.put("value", "1"); conditionB.put("formulaid", "B"); conditions.add(conditionB); JSONObject conditionC = new JSONObject(); conditionC.put("conditiontype", 0); conditionC.put("operator", 1); conditionC.put("value", hostgroupGet("group_gray")); conditionC.put("formulaid", "C"); conditions.add(conditionC); JSONObject conditionD = new JSONObject(); conditionD.put("conditiontype", 0); conditionD.put("operator", 0); conditionD.put("value", hostgroupGet(serverGroupDO.getName())); conditionD.put("formulaid", "D"); conditions.add(conditionD); filter.put("conditions", conditions); request.putParam("filter", filter); JSONObject getResponse = call(request); return getResultId(getResponse, "actionids"); }  }
ZabbixServiceImpl implements ZabbixService, InitializingBean { @Override public int actionCreate(ServerGroupDO serverGroupDO) { int actionid = actionGet(serverGroupDO); if (actionid != 0) return actionid; String usergrpName = serverGroupDO.getName().replace("group_", "users_"); ZabbixRequest request = ZabbixRequestBuilder.newBuilder() .method("action.create").build(); request.putParam("name", "Report problems to " + usergrpName); request.putParam("eventsource", 0); request.putParam("status", 0); request.putParam("esc_period", 3600); request.putParam("def_shortdata", "{TRIGGER.NAME}: {TRIGGER.STATUS}"); request.putParam("def_longdata", "ServerName:{HOST.NAME} IP:{HOST.IP}\r\nTrigger: {TRIGGER.NAME}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nItem values: {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\nOriginal event ID: {EVENT.ID}"); JSONArray operations = new JSONArray(); JSONObject operation = new JSONObject(); operation.put("operationtype", 0); operation.put("esc_period", 0); operation.put("esc_step_from", 1); operation.put("esc_step_to", 1); operation.put("evaltype", 0); JSONArray opmessage_grp = new JSONArray(); JSONObject usrgrp = new JSONObject(); usrgrp.put("usrgrpid", usergroupGet(usergrpName)); opmessage_grp.add(usrgrp); operation.put("opmessage_grp", opmessage_grp); JSONObject opmessage = new JSONObject(); opmessage.put("mediatypeid", 0); opmessage.put("default_msg", 1); opmessage.put("subject", "{TRIGGER.STATUS}: {TRIGGER.NAME}"); opmessage.put("message", "Trigger: {TRIGGER.NAME}\r\nTrigger status: {TRIGGER.STATUS}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nTrigger URL: {TRIGGER.URL}\r\n\r\nItem values:\r\n\r\n1. {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\n2. {ITEM.NAME2} ({HOST.NAME2}:{ITEM.KEY2}): {ITEM.VALUE2}\r\n3. {ITEM.NAME3} ({HOST.NAME3}:{ITEM.KEY3}): {ITEM.VALUE3}\r\n\r\nOriginal event ID: {EVENT.ID}"); operation.put("opmessage", opmessage); operations.add(operation); request.putParam("operations", operations); JSONObject filter = new JSONObject(); filter.put("evaltype", 1); JSONArray conditions = new JSONArray(); JSONObject conditionA = new JSONObject(); conditionA.put("conditiontype", 16); conditionA.put("operator", 7); conditionA.put("value", ""); conditionA.put("formulaid", "A"); conditions.add(conditionA); JSONObject conditionB = new JSONObject(); conditionB.put("conditiontype", 5); conditionB.put("operator", 0); conditionB.put("value", "1"); conditionB.put("formulaid", "B"); conditions.add(conditionB); JSONObject conditionC = new JSONObject(); conditionC.put("conditiontype", 0); conditionC.put("operator", 1); conditionC.put("value", hostgroupGet("group_gray")); conditionC.put("formulaid", "C"); conditions.add(conditionC); JSONObject conditionD = new JSONObject(); conditionD.put("conditiontype", 0); conditionD.put("operator", 0); conditionD.put("value", hostgroupGet(serverGroupDO.getName())); conditionD.put("formulaid", "D"); conditions.add(conditionD); filter.put("conditions", conditions); request.putParam("filter", filter); JSONObject getResponse = call(request); return getResultId(getResponse, "actionids"); }  @Override String getApiVersion(); @Override boolean hostExists(ServerDO serverDO); @Override int hostGetStatus(ServerDO serverDO); @Deprecated int hostGetByIP(String ip); @Deprecated int hostGetByName(String name); int proxyGet(String hostname); boolean hostgroupCreate(String name); int templateGet(String name); int usergroupGet(String usergroup); @Override BusinessWrapper<Boolean> userCreate(UserDO userDO); @Override int usergroupCreate(ServerGroupDO serverGroupDO); @Override int userGet(UserDO userDO); @Override BusinessWrapper<Boolean> userDelete(UserDO userDO); @Override BusinessWrapper<Boolean> syncUser(); void cleanZabbixUser(); @Override BusinessWrapper<Boolean> checkUser(); @Override BusinessWrapper<Boolean> userUpdate(UserDO userDO); @Deprecated JSONObject itemGetAll(ServerDO serverDO); int itemGet(ServerDO serverDO, String itemName, String itemKey); @Override int actionCreate(ServerGroupDO serverGroupDO); @Override JSONObject historyGet(ServerDO serverDO, String itemName, String itemKey, int historyType, int limit); @Override JSONObject historyGet(ServerDO serverDO, String itemName, String itemKey, int historyType, String timestampFrom, String timestampTill); void api(int statusType, String key, String project, String group, String env); @Override BusinessWrapper<Boolean> refresh(); @Override BusinessWrapper<Boolean> addMonitor(long serverId); @Override BusinessWrapper<Boolean> delMonitor(long serverId); @Override BusinessWrapper<Boolean> disableMonitor(long serverId); @Override BusinessWrapper<Boolean> enableMonitor(long serverId); @Override BusinessWrapper<Boolean> ci(String key, int type, String project, String group, String env, Long deployId, String bambooDeployVersion,
                                       int bambooBuildNumber, String bambooDeployProject, boolean bambooDeployRollback,
                                       String bambooManualBuildTriggerReasonUserName, int errorCode, String branchName, int deployType); int checkUserInUsergroup(UserDO userDO, ServerGroupDO serverGroupDO); @Override void afterPropertiesSet(); }
ZabbixServiceImpl implements ZabbixService, InitializingBean { @Override public int actionCreate(ServerGroupDO serverGroupDO) { int actionid = actionGet(serverGroupDO); if (actionid != 0) return actionid; String usergrpName = serverGroupDO.getName().replace("group_", "users_"); ZabbixRequest request = ZabbixRequestBuilder.newBuilder() .method("action.create").build(); request.putParam("name", "Report problems to " + usergrpName); request.putParam("eventsource", 0); request.putParam("status", 0); request.putParam("esc_period", 3600); request.putParam("def_shortdata", "{TRIGGER.NAME}: {TRIGGER.STATUS}"); request.putParam("def_longdata", "ServerName:{HOST.NAME} IP:{HOST.IP}\r\nTrigger: {TRIGGER.NAME}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nItem values: {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\nOriginal event ID: {EVENT.ID}"); JSONArray operations = new JSONArray(); JSONObject operation = new JSONObject(); operation.put("operationtype", 0); operation.put("esc_period", 0); operation.put("esc_step_from", 1); operation.put("esc_step_to", 1); operation.put("evaltype", 0); JSONArray opmessage_grp = new JSONArray(); JSONObject usrgrp = new JSONObject(); usrgrp.put("usrgrpid", usergroupGet(usergrpName)); opmessage_grp.add(usrgrp); operation.put("opmessage_grp", opmessage_grp); JSONObject opmessage = new JSONObject(); opmessage.put("mediatypeid", 0); opmessage.put("default_msg", 1); opmessage.put("subject", "{TRIGGER.STATUS}: {TRIGGER.NAME}"); opmessage.put("message", "Trigger: {TRIGGER.NAME}\r\nTrigger status: {TRIGGER.STATUS}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nTrigger URL: {TRIGGER.URL}\r\n\r\nItem values:\r\n\r\n1. {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\n2. {ITEM.NAME2} ({HOST.NAME2}:{ITEM.KEY2}): {ITEM.VALUE2}\r\n3. {ITEM.NAME3} ({HOST.NAME3}:{ITEM.KEY3}): {ITEM.VALUE3}\r\n\r\nOriginal event ID: {EVENT.ID}"); operation.put("opmessage", opmessage); operations.add(operation); request.putParam("operations", operations); JSONObject filter = new JSONObject(); filter.put("evaltype", 1); JSONArray conditions = new JSONArray(); JSONObject conditionA = new JSONObject(); conditionA.put("conditiontype", 16); conditionA.put("operator", 7); conditionA.put("value", ""); conditionA.put("formulaid", "A"); conditions.add(conditionA); JSONObject conditionB = new JSONObject(); conditionB.put("conditiontype", 5); conditionB.put("operator", 0); conditionB.put("value", "1"); conditionB.put("formulaid", "B"); conditions.add(conditionB); JSONObject conditionC = new JSONObject(); conditionC.put("conditiontype", 0); conditionC.put("operator", 1); conditionC.put("value", hostgroupGet("group_gray")); conditionC.put("formulaid", "C"); conditions.add(conditionC); JSONObject conditionD = new JSONObject(); conditionD.put("conditiontype", 0); conditionD.put("operator", 0); conditionD.put("value", hostgroupGet(serverGroupDO.getName())); conditionD.put("formulaid", "D"); conditions.add(conditionD); filter.put("conditions", conditions); request.putParam("filter", filter); JSONObject getResponse = call(request); return getResultId(getResponse, "actionids"); }  @Override String getApiVersion(); @Override boolean hostExists(ServerDO serverDO); @Override int hostGetStatus(ServerDO serverDO); @Deprecated int hostGetByIP(String ip); @Deprecated int hostGetByName(String name); int proxyGet(String hostname); boolean hostgroupCreate(String name); int templateGet(String name); int usergroupGet(String usergroup); @Override BusinessWrapper<Boolean> userCreate(UserDO userDO); @Override int usergroupCreate(ServerGroupDO serverGroupDO); @Override int userGet(UserDO userDO); @Override BusinessWrapper<Boolean> userDelete(UserDO userDO); @Override BusinessWrapper<Boolean> syncUser(); void cleanZabbixUser(); @Override BusinessWrapper<Boolean> checkUser(); @Override BusinessWrapper<Boolean> userUpdate(UserDO userDO); @Deprecated JSONObject itemGetAll(ServerDO serverDO); int itemGet(ServerDO serverDO, String itemName, String itemKey); @Override int actionCreate(ServerGroupDO serverGroupDO); @Override JSONObject historyGet(ServerDO serverDO, String itemName, String itemKey, int historyType, int limit); @Override JSONObject historyGet(ServerDO serverDO, String itemName, String itemKey, int historyType, String timestampFrom, String timestampTill); void api(int statusType, String key, String project, String group, String env); @Override BusinessWrapper<Boolean> refresh(); @Override BusinessWrapper<Boolean> addMonitor(long serverId); @Override BusinessWrapper<Boolean> delMonitor(long serverId); @Override BusinessWrapper<Boolean> disableMonitor(long serverId); @Override BusinessWrapper<Boolean> enableMonitor(long serverId); @Override BusinessWrapper<Boolean> ci(String key, int type, String project, String group, String env, Long deployId, String bambooDeployVersion,
                                       int bambooBuildNumber, String bambooDeployProject, boolean bambooDeployRollback,
                                       String bambooManualBuildTriggerReasonUserName, int errorCode, String branchName, int deployType); int checkUserInUsergroup(UserDO userDO, ServerGroupDO serverGroupDO); @Override void afterPropertiesSet(); static final String zabbix_host_monitor_public_ip; static final String zabbix_proxy_id; static final String zabbix_proxy_name; static final int hostStatusDisable; static final int hostStatusEnable; static final int isMonitor; static final int noMonitor; }