示例#1
0
    public async Task ExecuteRegisterTasksAsync(CancellationToken cancel = default)
    {
        using (var session = new CactiSession(this.BaseUrl, this.Username, this.Password))
        {
            Con.WriteLine($"Logging in for {this.BaseUrl} ...");

            await session.EnsureLoginAsync(cancel);

            Con.WriteLine("Login Ok.");

            foreach (var h in Hosts)
            {
                Con.WriteLine($"Registering or finding the host {h.Description} - {h.Hostname} ...");

                try
                {
                    int hostId = await session.RegisterOrGetHostIdAsync(h, cancel);

                    Con.WriteLine($"Enabling items...");

                    await session.EnableGraphItemsAsync(hostId, Items, cancel);

                    Con.WriteLine("Ok.");
                }
                catch (Exception ex)
                {
                    ex._Print();
                }

                Con.WriteLine();
            }
        }
    }
示例#2
0
    public static async Task DownloadGraphsAsync(string destDir, string baseUrl, string username, string password, IEnumerable <int> targetGraphIdList, CancellationToken cancel = default)
    {
        using var r = new CactiSession(baseUrl, username, password);

        List <CactiDownloadedGraph> list = new List <CactiDownloadedGraph>();

        foreach (int id in targetGraphIdList.Distinct())
        {
            await r.EnsureLoginAsync(cancel);

            Con.WriteLine($"Downloading id = {id} ...");

            try
            {
                var tmp = await r.DownloadGraphAsync(id, 1, 6, cancel);

                tmp._DoForEach(x => list.Add(x));
            }
            catch
            {
            }
        }

        if (list.Count == 0)
        {
            throw new CoresException($"Download cacti graphs failed.");
        }

        Con.WriteLine("Done.");

        foreach (var g in list)
        {
            string fn = destDir._CombinePath("graph_size_" + g.Size + "_id_" + g.GraphId.ToString("D5") + "_rra_" + g.RraId.ToString("D5") + ".png");

            Lfs.WriteDataToFile(fn, g.Data, FileFlags.AutoCreateDirectory);
        }
    }