gpt4 book ai didi

com.sdg.cmdb.service.impl.ZabbixServiceImpl类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 11:12:43 26 4
gpt4 key购买 nike

本文整理了Java中com.sdg.cmdb.service.impl.ZabbixServiceImpl类的一些代码示例,展示了ZabbixServiceImpl类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZabbixServiceImpl类的具体详情如下:
包路径:com.sdg.cmdb.service.impl.ZabbixServiceImpl
类名称:ZabbixServiceImpl

ZabbixServiceImpl介绍

[英]Created by liangjian on 2016/12/16.
[中]梁健于2016年12月16日创作。

代码示例

代码示例来源:origin: ixrjog/opsCloud

/**
 * 初始化
 *
 * @return
 */
private void init() {
  HashMap<String, String> configMap = acqConifMap();
  String zabbixApiUrl = configMap.get(ZabbixItemEnum.ZABBIX_API_URL.getItemKey());
  String zabbixApiUser = configMap.get(ZabbixItemEnum.ZABBIX_API_USER.getItemKey());
  String zabbixAipPasswd = configMap.get(ZabbixItemEnum.ZABBIX_API_PASSWD.getItemKey());
  logger.info("Zabbix login api url : {}", zabbixApiUrl);
  RequestConfig requestConfig = RequestConfig.custom()
      .setConnectTimeout(5 * 1000).setConnectionRequestTimeout(5 * 1000)
      .setSocketTimeout(5 * 1000).build();
  PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
  CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(connManager)
      .setDefaultRequestConfig(requestConfig).build();
  setUrl(zabbixApiUrl);
  setHttpClient(httpclient);
  boolean login = login(zabbixApiUser, zabbixAipPasswd);
  if (!login) {
    logger.error("zabbix 登陆失败");
  }
}

代码示例来源:origin: ixrjog/opsCloud

/**
 * 普通服务器监控添加(废弃)
 *
 * @return
 */
private boolean hostCreate(ServerDO serverDO) {
  if (hostExists(serverDO)) return true;
  if (!hostgroupCreate(serverDO)) return false;
  ZabbixRequest request = ZabbixRequestBuilder.newBuilder()
      .method("host.create").build();
  request.putParam("host", acqZabbixServerName(serverDO));
  request.putParam("interfaces", acqInterfaces(serverDO));
  request.putParam("groups", acqGroup(serverDO));
  request.putParam("templates", acqTemplate(serverDO));
  request.putParam("macros", acqMacros(serverDO));
  int proxyid = proxyGet(serverDO);
  if (proxyid != 0) {
    request.putParam("proxy_hostid", proxyid);
  }
  JSONObject getResponse = call(request);
  int hostids = getResultId(getResponse, "hostids");
  if (hostids == 0) return false;
  return true;
}

代码示例来源:origin: ixrjog/opsCloud

/**
 * 获取当前主机的接口(java类有jmx)
 *
 * @return
 */
private JSONArray acqInterfaces(ServerDO serverDO) {
  if (serverDO == null) return null;
  ConfigPropertyDO confPropertyDO = configDao.getConfigPropertyByName("TOMCAT_JMX_rmiRegistryPortPlatform_OPT");
  JSONArray interfaces = new JSONArray();
  String ip = this.acqServerMonitorIp(serverDO);
  interfaces.add(buildInterfaces(ip, 1, "10050"));
  if (confPropertyDO != null && !confPropertyDO.getProValue().isEmpty()) {
    String port = this.acqServerGroupPropertiesValue(serverDO, confPropertyDO);
    if (port != null && !port.isEmpty())
      interfaces.add(buildInterfaces(ip, 4, port));
  }
  return interfaces;
}

代码示例来源:origin: ixrjog/opsCloud

/**
 * 内网ip查询hostid
 *
 * @return
 */
private int hostGet(ServerDO serverDO) {
  if (serverDO == null) return 0;
  JSONObject filter = new JSONObject();
  filter.put("ip", acqServerMonitorIp(serverDO));
  ZabbixRequest request = ZabbixRequestBuilder.newBuilder()
      .method("host.get").paramEntry("filter", filter)
      .build();
  JSONObject getResponse = call(request);
  return getResultId(getResponse, "hostid");
}

代码示例来源:origin: ixrjog/opsCloud

ZabbixRequest request = ZabbixRequestBuilder.newBuilder()
    .method("user.update").build();
request.putParam("userid", userGet(userDO));
request.putParam("name", userDO.getDisplayName());
request.putParam("usrgrps", acqUsergrps(userDO));
JSONArray userMedias = new JSONArray();
userMedias.add(acqUserMedias(1, userDO.getMail()));
if (userDO.getMobile() != null && !userDO.getMobile().isEmpty()) {
  userMedias.add(acqUserMedias(3, userDO.getMobile()));
JSONObject getResponse = call(request);
int userids = getResultId(getResponse, "userids");
if (userids != 0) {
  userDO.setZabbixAuthed(UserDO.ZabbixAuthType.authed.getCode());

代码示例来源:origin: ixrjog/opsCloud

@Override
public ZabbixHost getHost(long serverId) {
  ServerDO serverDO = serverDao.getServerInfoById(serverId);
  if (serverDO == null) return new ZabbixHost();
  List<ZabbixTemplateVO> templates = getTemplates(serverDO.getServerGroupId());
  ZabbixHost host = new ZabbixHost(templates);
  invokeProxy(serverDO.getServerGroupId(), host);
  host.setHost(serverDO.acqServerName());
  host.setIp(acqServerMonitorIp(serverDO));
  return host;
}

代码示例来源:origin: ixrjog/opsCloud

/**
 * 获取当前主机的Zabbix监控模版
 *
 * @return
 */
private JSONArray acqTemplate(ServerDO serverDO) {
  if (serverDO == null) return null;
  JSONArray templates = new JSONArray();
  ConfigPropertyDO confPropertyDO = configDao.getConfigPropertyByName("TOMCAT_APP_NAME_OPT");
  int templateid = 0;
  if (confPropertyDO != null) {
    String value = this.acqServerGroupPropertiesValue(serverDO, confPropertyDO);
    if (value == null || value.isEmpty()) {
      templateid = templateGet("Template OS Linux");
    } else {
      templateid = templateGet("Template Java");
    }
    JSONObject template = new JSONObject();
    template.put("templateid", templateid);
    templates.add(template);
    return templates;
  }
  return null;
}

代码示例来源:origin: ixrjog/opsCloud

/**
 * 获取zabbixProxyId
 * 1:zabbix_proxy_id
 * 2:zabbix_proxy_name
 *
 * @return
 */
private int proxyGet(ServerDO serverDO) {
  if (serverDO == null) return 0;
  ConfigPropertyDO confPropertyDO = configDao.getConfigPropertyByName(zabbix_proxy_id);
  if (confPropertyDO != null && !confPropertyDO.getProValue().isEmpty()) {
    String value = acqServerPropertiesValue(serverDO, confPropertyDO);
    if (value != null && !value.isEmpty()) return Integer.valueOf(value);
  }
  confPropertyDO = configDao.getConfigPropertyByName(zabbix_proxy_name);
  if (confPropertyDO != null && !confPropertyDO.getProValue().isEmpty()) {
    String value = acqServerPropertiesValue(serverDO, confPropertyDO);
    if (value != null && !value.isEmpty()) return proxyGet(confPropertyDO.getProValue());
  }
  if (serverDO.getServerType() == 2) {
    return proxyGet("proxy1.zabbix3.51xianqu.net");
  }
  return 0;
}

代码示例来源:origin: ixrjog/opsCloud

/**
 * 检查key
 *
 * @param key
 * @return
 */
private boolean apiCheckKey(String key) {
  HashMap<String, String> configMap = acqConifMap();
  String zabbixApiKey = configMap.get(ZabbixItemEnum.ZABBIX_API_KEY.getItemKey());
  if (key == null) {
    logger.error("cmdb.zabbix.api.key为空");
    return false;
  }
  if (!key.equals(zabbixApiKey)) {
    logger.error("cmdb.zabbix.api.key不匹配");
    return false;
  }
  return true;
}

代码示例来源:origin: ixrjog/opsCloud

/**
 * 获取当前主机的宏(macros)
 *
 * @return
 */
private JSONArray acqMacros(ServerDO serverDO) {
  if (serverDO == null) return null;
  ConfigPropertyDO confPropertyDO = configDao.getConfigPropertyByName("TOMCAT_APP_NAME_OPT");
  if (confPropertyDO == null) return null;
  String appName = this.acqServerGroupPropertiesValue(serverDO, confPropertyDO);
  if (appName != null && !appName.isEmpty()) {
    JSONArray macros = new JSONArray();
    confPropertyDO = configDao.getConfigPropertyByName("TOMCAT_HTTP_PORT_OPT");
    String httpPort = this.acqServerGroupPropertiesValue(serverDO, confPropertyDO);
    JSONObject jsonAppName = new JSONObject();
    jsonAppName.put("macro", "{$APP_NAME}");
    jsonAppName.put("value", appName);
    JSONObject jsonHttpPort = new JSONObject();
    jsonHttpPort.put("macro", "{$HTTP_PORT}");
    jsonHttpPort.put("value", httpPort);
    macros.add(jsonAppName);
    macros.add(jsonHttpPort);
    return macros;
  }
  return null;
}

代码示例来源:origin: ixrjog/opsCloud

/**
 * 获取主机用于zabbix监控的接口ip
 *
 * @return
 */
private String acqServerMonitorIp(ServerDO serverDO) {
  if (serverDO == null) return null;
  ConfigPropertyDO confPropertyDO = configDao.getConfigPropertyByName(zabbix_host_monitor_public_ip);
  String value = acqServerPropertiesValue(serverDO, confPropertyDO);
  if (value == null || value.equalsIgnoreCase("false")) {
    return serverDO.getInsideIp();
  }
  return serverDO.getPublicIp();
}

代码示例来源:origin: ixrjog/opsCloud

request.putParam("name", userDO.getDisplayName());
request.putParam("passwd", "");
request.putParam("usrgrps", acqUsergrps(userDO));
JSONArray userMedias = new JSONArray();
userMedias.add(acqUserMedias(1, userDO.getMail()));
if (userDO.getMobile() != null && !userDO.getMobile().isEmpty()) {
  userMedias.add(acqUserMedias(3, userDO.getMobile()));
JSONObject getResponse = call(request);
int userids = getResultId(getResponse, "userids");

代码示例来源:origin: ixrjog/opsCloud

/**
 * 查询主机监控状态
 *
 * @param serverDO
 * @return
 */
@Override
public int hostGetStatus(ServerDO serverDO) {
  if (serverDO == null) return 0;
  JSONObject filter = new JSONObject();
  filter.put("ip", acqServerMonitorIp(serverDO));
  JSONObject getResponse = call(ZabbixRequestBuilder.newBuilder()
      .method("host.get").paramEntry("filter", filter)
      .build());
  return getResultId(getResponse, "status");
}

代码示例来源:origin: ixrjog/opsCloud

private boolean hostCreate(ServerDO serverDO, ZabbixHost host) {
  if (hostExists(serverDO)) return true;
  if (!hostgroupCreate(serverDO)) return false;
  ZabbixRequest request = ZabbixRequestBuilder.newBuilder()
      .method("host.create").build();
  request.putParam("host", serverDO.acqServerName());
  request.putParam("interfaces", acqInterfaces(serverDO));
  request.putParam("groups", acqGroup(serverDO));
  request.putParam("templates", acqTemplate(host.getTemplates()));
  if (host.isUseProxy()) {
    for (ZabbixProxy zp : host.getProxys()) {
      if (zp.isSelected()) {
        request.putParam("proxy_hostid", proxyGet(zp.getHost()));
      }
      break;
    }
  }
  JSONObject getResponse = call(request);
  int hostids = getResultId(getResponse, "hostids");
  if (hostids == 0) return false;
  return true;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com