Example #1
0
        private List <ZabHistoryItem> _coreReadData(int hoursBack, IEnumerable <string> itemIds, int historyType)
        {
            if (zabbix.loggedOn == false)
            {
                return(null);
            }

            /*
             * Output can be “shorten”, “refer”, “extend” and array of db field names.
             *
             * -shorten: only ids of elements are returned. (for hosts it's hostid, for items itemid etc)
             * -refer: element ids are returned with element ids that were used in query.
             * For example request item.get(output: refer, hostids: [1,2,3])) will return items with itemids and hostids.
             * -extend: all db fields of element are returned (select *)
             * -array of db fields: listed db fields are returned
             */

            try
            {
                var command = "history.get";
                var p       = new
                {
                    output = "extend",
                    //itemids = new String[] { "25859","26117","26879"},
                    itemids   = itemIds.Distinct().ToArray(),
                    history   = historyType,
                    sortfield = "clock",
                    sortorder = "ASC",
                    time_from = Devmasters.DT.Util.ToEpochTimeFromUTC(DateTime.UtcNow.AddHours(-1 * hoursBack)),
                    time_till = Devmasters.DT.Util.ToEpochTimeFromUTC(DateTime.UtcNow)
                };
                var res = zabbix.objectResponse(command, p);
                List <ZabHistoryItem> history = new List <ZabHistoryItem>();
                foreach (var r in res.result)
                {
                    var h = new ZabHistoryItem()
                    {
                        itemId = r.itemid,
                        clock  = Devmasters.DT.Util.FromEpochTimeToUTC(Convert.ToInt64(r.clock)).ToLocalTime(),
                        value  = HlidacStatu.Util.ParseTools.ToDecimal(r.value)
                    };
                    history.Add(h);
                }

                return(history);
            }
            catch (Exception e)
            {
                HlidacStatu.Util.Consts.Logger.Fatal("ZabTools webyList cache", e);
                return(null);
            }
        }
Example #2
0
        private List <ZabHistoryItem> ReadSslData(int hoursBack, IEnumerable <string> itemIds)
        {
            if (zabbix.loggedOn == false)
            {
                return(null);
            }

            int limitForNumOfItems = 60;
            var res = new List <ZabHistoryItem>();

            try
            {
                foreach (var chunk in itemIds.Chunk(limitForNumOfItems))
                {
                    var command = "history.get";
                    var p       = new
                    {
                        output = "extend",
                        //itemids = new String[] { "25859","26117","26879"},
                        itemids   = itemIds.Distinct().ToArray(),
                        history   = 4,
                        sortfield = "clock",
                        sortorder = "ASC",
                        time_from = Devmasters.DT.Util.ToEpochTimeFromUTC(DateTime.UtcNow.AddHours(-1 * hoursBack)),
                        time_till = Devmasters.DT.Util.ToEpochTimeFromUTC(DateTime.UtcNow)
                    };
                    var zres = zabbix.objectResponse(command, p);
                    List <ZabHistoryItem> history = new List <ZabHistoryItem>();
                    foreach (var r in zres.result)
                    {
                        var h = new ZabHistoryItem()
                        {
                            itemId = r.itemid,
                            clock  = Devmasters.DT.Util.FromEpochTimeToUTC(Convert.ToInt64(r.clock)),
                            svalue = r.value
                        };
                        history.Add(h);
                    }
                    res.AddRange(history);
                }

                return(res);
            }
            catch (Exception e)
            {
                HlidacStatu.Util.Consts.Logger.Fatal("ZabTools webyList cache", e);
                return(null);
            }
        }
        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();
        }
Example #4
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(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();
        }