public ZabHostAvailability_Intervals(ZabHost host, IEnumerable <ZabHistoryItem> measures, DateTime lastDate)
        {
            this.Host = host;
            List <ZabAvailabilityInterval> interv = new List <ZabAvailabilityInterval>();
            DateTime debugt = new DateTime(2017, 12, 7, 17, 08, 00);
            var      data   = measures.OrderBy(m => m.clock).ToArray();

            for (int i = 0; i < data.Length - 1; i++)
            {
                var      m      = data[i];
                Statuses status = ZabAvailability.GetStatus(m.value);

                if (i > 0 && (m.clock - data[i - 1].clock).TotalMinutes > 3) //pokud chybi data za vice nez 3 min, oznat je cervene
                {
                    interv.Add(new ZabAvailabilityInterval(data[i - 1].clock, m.clock, Statuses.Nedostupné));
                }

                //hledej kdy tento status konci
                var j = 1;
                while (
                    i + j < data.Length - 1 &&
                    ZabAvailability.GetStatus(data[i + j].value) == status &&
                    (i > 0 && (data[i + j].clock - data[i + j - 1].clock).TotalMinutes < 3)
                    )
                {
                    j++;
                }
                interv.Add(new ZabAvailabilityInterval(m.clock, data[i + j].clock, status));
                i = i + (j - 1);
            }
            this.Intervals = interv.ToArray();
        }
Exemplo n.º 2
0
        public IEnumerable <ZabHost> GetHostsFromGroup(string groupname)
        {
            if (zabbix.loggedOn == false)
            {
                return(null);
            }

            try
            {
                var command = "hostgroup.get";
                var res     = zabbix.objectResponse(command, new
                {
                    output = "shorten",
                    filter = new { name = new string[] { groupname } }
                }
                                                    );
                if (res.result == null)
                {
                    return(null);
                }
                string groupId = res.result[0].groupid;

                command = "item.get";
                Dictionary <string, string> keysearch = new Dictionary <string, string>();
                keysearch.Add("key_", "web.test.time[CheckWeb,HP,resp]");

                res = zabbix.objectResponse(command, new
                {
                    selectHosts = new string[] { "hostid", "host", "name", "description" },
                    output      = "extend",
                    webitems    = true,
                    groupids    = groupId,
                    search      = keysearch
                });
                var tmp = new List <ZabHost>();

                foreach (var r in res.result)
                {
                    if (r.lastclock != "0")
                    {
                        ZabHost h = new ZabHost(r.hosts[0].hostid, r.hosts[0].host, r.hosts[0].name, r.hosts[0].description);
                        h.itemIdResponseTime = r.itemid;
                        tmp.Add(h);
                    }
                }

                return(tmp);
            }
            catch (Exception e)
            {
                HlidacStatu.Util.Consts.Logger.Fatal("ZabTools webyList cache", e);
                return(null);
            }
        }
Exemplo n.º 3
0
        public static ZabHostAvailability GetHostAvailabilityLong(ZabHost host)
        {
            Devmasters.Cache.LocalMemory.LocalMemoryCache <ZabHostAvailability> webData =
                new Devmasters.Cache.LocalMemory.LocalMemoryCache <ZabHostAvailability>(
                    TimeSpan.FromMinutes(10), "statniweby_host_" + host.hostid, (obj) =>
            {
                ZabHostAvailability d = null;
                using (var zr = new ZabbixReader())
                {
                    d = zr.GetAvailability_Raw(7 * 24 + 1, new ZabHost[] { host }, true).FirstOrDefault();
                    HlidacStatu.Util.Consts.Logger.Info("Cache statniweby_host_" + host.hostid + " refreshnuta");
                    return(d);
                }
            });

            try
            {
                return(webData.Get());
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public List <ZabHost> RefreshHosts(int priority)
        {
            if (zabbix.loggedOn == false)
            {
                return(null);
            }

            try
            {
                var command = "hostgroup.get";
                var res     = zabbix.objectResponse(command, new
                {
                    output = "shorten",
                    filter = new { name = new string[] { priority + ". priorita" } }
                }
                                                    );
                string groupId = res.result[0].groupid;

                command = "item.get";
                Dictionary <string, string> keysearch = new Dictionary <string, string>();
                keysearch.Add("key_", "web.test.time[CheckWeb,HP,resp]");

                //keysearch.Add("key_", "ssl.json");

                res = zabbix.objectResponse(command, new
                {
                    selectHosts = new string[] { "hostid", "host", "name", "description" },
                    output      = "extend",
                    webitems    = true,
                    groupids    = groupId,
                    search      = keysearch
                });
                var tmp = new List <ZabHost>();

                foreach (var r in res.result)
                {
                    if (true || r.lastclock != "0")
                    {
                        ZabHost h = new ZabHost(r.hosts[0].hostid, r.hosts[0].host, r.hosts[0].name, r.hosts[0].description, new string[] { priority.ToString() });

                        h.itemIdResponseTime = r.itemid;

                        tmp.Add(h);
                    }
                }

                //read response code
                command = "item.get";
                keysearch.Clear(); keysearch.Add("key_", "web.test.rspcode[CheckWeb,HP]");
                res = zabbix.objectResponse(command, new
                {
                    selectHosts = new string[] { "hostid", "host", "name", "description" },
                    output      = "extend",
                    webitems    = true,
                    groupids    = groupId,
                    search      = keysearch
                });
                foreach (var r in res.result)
                {
                    if (true || r.lastclock != "0")
                    {
                        var hostid = r.hosts[0].hostid;
                        var exist  = tmp.Where(m => m.hostid == hostid).FirstOrDefault();
                        if (exist != null)
                        {
                            exist.itemIdResponseCode = r.itemid;
                        }
                        else
                        {
                            ZabHost h = new ZabHost(r.hosts[0].hostid, r.hosts[0].host, r.hosts[0].name, r.hosts[0].description, new string[] { priority.ToString() });
                            h.itemIdResponseCode = r.itemid;
                            tmp.Add(h);
                        }
                    }
                }

                //read Ssl.Json
                command = "item.get";
                keysearch.Clear(); keysearch.Add("key_", "ssl.json");
                res = zabbix.objectResponse(command, new
                {
                    selectHosts = new string[] { "hostid", "host", "name", "description" },
                    output      = "extend",
                    groupids    = groupId,
                    search      = keysearch
                });
                foreach (var r in res.result)
                {
                    if (true || r.lastclock != "0")
                    {
                        var hostid = r.hosts[0].hostid;
                        var exist  = tmp.Where(m => m.hostid == hostid).FirstOrDefault();
                        if (exist != null)
                        {
                            exist.itemIdSsl = r.itemid;
                        }
                        else
                        {
                            ZabHost h = new ZabHost(r.hosts[0].hostid, r.hosts[0].host, r.hosts[0].name, r.hosts[0].description, new string[] { priority.ToString() });
                            h.itemIdSsl = r.itemid;
                            tmp.Add(h);
                        }
                    }
                }



                if (priority == 0)
                {
                    //add EET, NEN API
                    res = zabbix.objectResponse("item.get", new
                    {
                        selectHosts = new string[] { "hostid", "host", "name", "description" },
                        output      = "extend",
                        itemids     = new string[] { "27939", "30053" }
                    });


                    foreach (var r in res.result)
                    {
                        if (r.lastclock != "0")
                        {
                            ZabHost h = new ZabHost(r.hosts[0].hostid, r.hosts[0].host, r.hosts[0].name, r.hosts[0].description, new string[] { priority.ToString() });
                            h.itemIdResponseTime = r.itemid;

                            tmp.Add(h);
                        }
                    }
                }
                return(tmp);
            }
            catch (Exception e)
            {
                HlidacStatu.Util.Consts.Logger.Fatal("ZabTools webyList cache", e);
                return(null);
            }
        }
Exemplo n.º 5
0
 public ZabHostSslStatus(ZabHost host, IEnumerable <EndpointStatus> endpoints, DateTime time)
 {
     this.Host      = host;
     this.Endpoints = endpoints.ToArray();
     this.Time      = time;
 }
Exemplo n.º 6
0
        public ZabHostAvailability(ZabHost host, IEnumerable <ZabHistoryItem> measures, bool fillMissingWithNull = false, DateTime?lastExpectedTime = null)
        {
            if (lastExpectedTime.HasValue == false)
            {
                lastExpectedTime = DateTime.Now.AddMinutes(-1);
            }

            this.Host = host;
            List <ZabAvailability> avail = new List <ZabAvailability>();
            bool            stop         = false;
            ZabHistoryItem  first        = measures.First();
            ZabAvailability prev         = new ZabAvailability()
            {
                Time = first.clock, Response = first.value
            };

            avail.Add(prev);
            var data = measures.OrderBy(m => m.clock).ToArray();

            for (int i = 1; i < data.Length; i++)
            {
                var curr = data[i];

                if (fillMissingWithNull)
                {
                    var diffInMin = (curr.clock - prev.Time).TotalMinutes;
                    if (diffInMin > 2.5) //velka mezera, dopln null
                    {
                        for (int j = 1; j < diffInMin - 1; j++)
                        {
                            DateTime prevTime = prev.Time.AddMinutes(j);

                            if (SkipThisTime(this.Host.hostid, prevTime) == false)
                            {
                                avail.Add(new ZabAvailability()
                                {
                                    Time = prevTime, Response = ZabAvailability.TimeOuted
                                });
                            }
                        }
                    }
                }

                if (SkipThisTime(this.Host.hostid, curr.clock) == false)
                {
                    avail.Add(new ZabAvailability()
                    {
                        Time = curr.clock, Response = curr.value, DownloadSpeed = null, HttpStatusCode = null
                    });
                }

                prev = avail.Last();
            }
            //check last missing value
            var currLast = data[data.Length - 1];

            if ((lastExpectedTime.Value - currLast.clock).TotalMinutes > 5)
            {
                var diffInMin = (lastExpectedTime.Value - currLast.clock).TotalMinutes;
                if (diffInMin > 2.5) //velka mezera, dopln null
                {
                    for (int j = 1; j < diffInMin - 1; j++)
                    {
                        DateTime prevTime = prev.Time.AddMinutes(j);

                        if (SkipThisTime(this.Host.hostid, prevTime) == false)
                        {
                            avail.Add(new ZabAvailability()
                            {
                                Time = prevTime, Response = ZabAvailability.TimeOuted
                            });
                        }
                    }
                }
            }


            this.Data = avail.ToArray();
        }
        public ZabHostAvailability_PerMin(ZabHost host, IEnumerable <ZabHistoryItem> measures)
        {
            this.Host = host;
            List <ZabAvailability> avail = new List <ZabAvailability>();

            ZabHistoryItem  first = measures.First();
            ZabAvailability prev  = new ZabAvailability()
            {
                Time = RoundToMin(first.clock), Response = first.value
            };

            avail.Add(prev);
            var data = measures.OrderBy(m => m.clock).ToArray();

            for (int i = 1; i < data.Length; i++)
            {
                var curr      = data[i];
                var d         = RoundToMin(curr.clock);
                var diffInMin = (d - prev.Time).TotalMinutes;
                if (diffInMin > 3.5) //velka mezera, dopln null
                {
                    for (int j = 0; j < diffInMin; j++)
                    {
                        avail.Add(new ZabAvailability()
                        {
                            Time = d.AddMinutes(j), Response = null
                        });
                    }
                }
                else if (diffInMin > 1.5) //mala mezera, zopakuju posledni stav
                {
                    for (int j = 0; j < diffInMin; j++)
                    {
                        avail.Add(new ZabAvailability()
                        {
                            Time = d.AddMinutes(j), Response = prev.Response, DownloadSpeed = prev.Response, HttpStatusCode = prev.HttpStatusCode
                        });
                    }
                }
                else if (diffInMin > 1) //ok
                {
                    avail.Add(new ZabAvailability()
                    {
                        Time = d, Response = curr.value, DownloadSpeed = null, HttpStatusCode = null
                    });
                }
                else if (diffInMin > 0) //mene nez 1 min
                {
                    //je nasleduji dal nez 1 min?
                    if (i < data.Length - 1 && (RoundToMin(data[i + 1].clock) - prev.Time).TotalMinutes > 2)
                    {
                        avail.Add(new ZabAvailability()
                        {
                            Time = d.AddMinutes(1), Response = curr.value, DownloadSpeed = null, HttpStatusCode = null
                        });
                    }
                    //jinak to preskoc
                }

                prev = avail.Last();
            }
            this.Data = avail.ToArray();
        }
        public ZabHostAvailability(ZabHost host, IEnumerable <ZabHistoryItem> measures, bool fillMissingWithNull = false, DateTime?lastExpectedTime = null)
        {
            if (lastExpectedTime.HasValue == false)
            {
                lastExpectedTime = DateTime.Now.AddMinutes(-1);
            }

            this.Host = host;
            List <ZabAvailability> avail = new List <ZabAvailability>();
            bool            stop         = false;
            ZabHistoryItem  first        = measures.First();
            ZabAvailability prev         = new ZabAvailability()
            {
                Time = first.clock, Response = first.value
            };

            avail.Add(prev);
            var data = measures.OrderBy(m => m.clock).ToArray();

            for (int i = 1; i < data.Length; i++)
            {
                var curr = data[i];

                if (fillMissingWithNull)
                {
                    var diffInMin = (curr.clock - prev.Time).TotalMinutes;
                    if (diffInMin > 2.5) //velka mezera, dopln null
                    {
                        for (int j = 1; j < diffInMin - 1; j++)
                        {
                            DateTime prevTime = prev.Time.AddMinutes(j);

                            bool skipIt = false;
                            foreach (var ign in ignoreIt)
                            {
                                if ((this.Host.hostid == ign.hostid || string.IsNullOrEmpty(ign.hostid)) &&
                                    (ign.from > prevTime || prevTime < ign.to)
                                    ) //vypadek na nasi strane
                                {
                                    skipIt = true;
                                    break;
                                }
                            }

                            if (skipIt == false)
                            {
                                avail.Add(new ZabAvailability()
                                {
                                    Time = prevTime, Response = ZabAvailability.TimeOuted
                                });
                            }
                        }
                    }
                }
                avail.Add(new ZabAvailability()
                {
                    Time = curr.clock, Response = curr.value, DownloadSpeed = null, HttpStatusCode = null
                });

                prev = avail.Last();
            }
            //check last missing value
            var currLast = data[data.Length - 1];

            if ((lastExpectedTime.Value - currLast.clock).TotalMinutes > 5)
            {
                var diffInMin = (lastExpectedTime.Value - currLast.clock).TotalMinutes;
                if (diffInMin > 2.5) //velka mezera, dopln null
                {
                    for (int j = 1; j < diffInMin - 1; j++)
                    {
                        DateTime prevTime = prev.Time.AddMinutes(j);

                        avail.Add(new ZabAvailability()
                        {
                            Time = prevTime, Response = ZabAvailability.TimeOuted
                        });
                    }
                }
            }


            this.Data = avail.ToArray();
        }