public bool TryCreateHost(string name) { ZabbixApi.Helper.Check.IsNotNullOrWhiteSpace(name, "name"); if (!TryCreateHostGroup("Metrics.NET")) { return(false); } using (var context = _contextCreator()) { try { var service = new ZabbixApi.Services.HostService(context); var host = service.GetByName(name); if (host == null) { if (IsIpAddress(name)) { host = new Host(); host.host = name; host.interfaces = host.interfaces ?? new List <HostInterface>(); host.interfaces.Add(new HostInterface() { type = HostInterface.InterfaceType.Agent, main = true, useip = true, ip = name, dns = "", port = "10050" }); host.groups = host.groups ?? new List <HostGroup>(); host.groups.Add(_HostGroupMetricsCache); host.Id = service.Create(host); } else { return(false); } } if (host.Id != null) { _HostCache = host; return(true); } else { return(false); } } catch (Exception ex) { MetricsErrorHandler.Handle(ex, string.Format("Error on create zabbix host, zabbix api {0}", _url)); return(false); } } }
public bool TryCreateHost(string name) { ZabbixApi.Helper.Check.IsNotNullOrWhiteSpace(name, "name"); if (!TryCreateHostGroup("Metrics.NET")) return false; using (var context = _contextCreator()) { try { var service = new ZabbixApi.Services.HostService(context); var host = service.GetByName(name); if (host == null) { if (IsIpAddress(name)) { host = new Host(); host.host = name; host.interfaces = host.interfaces ?? new List<HostInterface>(); host.interfaces.Add(new HostInterface() { type = HostInterface.InterfaceType.Agent, main = true, useip = true, ip = name, dns = "", port = "10050" }); host.groups = host.groups ?? new List<HostGroup>(); host.groups.Add(_HostGroupMetricsCache); host.Id = service.Create(host); } else { return false; } } if (host.Id != null) { _HostCache = host; return true; } else { return false; } } catch (Exception ex) { MetricsErrorHandler.Handle(ex, string.Format("Error on create zabbix host, zabbix api {0}", _url)); return false; } } }