Esempio n. 1
0
        private void run(int reportId)
        {
            string         url = HttpClient.GetUrlFromIp(Settings.Instance.ServerSettings.Server[ServerId].Address, Settings.Instance.ServerSettings.Server[ServerId].Port, Settings.Instance.ServerSettings.Server[ServerId].UseSsl);
            PrtgApiManager api = new PrtgApiManager(url, Settings.Instance.ServerSettings.Server[ServerId].Username, Settings.Instance.ServerSettings.Server[ServerId].Password, true);

            SetStatusText("Receiving data from the PRTG server...");
            SensorReport report          = Settings.Instance.ServerSettings.Server[ServerId].Groups[GroupId].Reports[reportId];
            string       tmpChannelsFile = HttpClient.GetHttpStream(api.GetSensorChannelNames(report.SensorId), "api_channels.xml");
            string       tmpDataFile     = HttpClient.GetHttpStream(api.GetHistoricSensorData(report.SensorId, report.Average.ToString(), StartDate, EndDate));
            string       chartPath       = HttpClient.GetHttpStream(api.GetSensorGraph(report.SensorId, report.Average.ToString(), StartDate, EndDate, 850, 270), "chart.png");
            string       percentileTmp   = string.Empty;

            if (report.HasPercentile)
            {
                percentileTmp = HttpClient.GetHttpStream(api.GetPercentile(report.SensorId, StartDate, EndDate, report.Percentile, report.PercentileMethod, report.PercentileAvg), "percentile.xml");
            }
            SensorData sensor = null;

            if (!bw.CancellationPending)
            {
                SetStatusText("Parsing data...");
                SensorDataXmlParser parser = new SensorDataXmlParser(report.SensorId);
                sensor = parser.parse(tmpChannelsFile, tmpDataFile);
                if (report.HasPercentile)
                {
                    parser.ParsePercentile(percentileTmp);
                }
                sensor.chartPath = chartPath;
            }
            if (!bw.CancellationPending)
            {
                SetStatusText("Running script...");
                if (sensor != null)
                {
                    ScriptEngine scr = new ScriptEngine(sensor, report.ScriptName, report.TemplateName, reportId, StartDate, EndDate);
                    scr.RunScript();
                    if (scr.error)
                    {
                        bw.CancelAsync();
                    }
                }
            }
            if (!bw.CancellationPending)
            {
                SetStatusText("Creating output...");
                Settings.Instance.ServerSettings.Server[ServerId].Groups[GroupId].Reports[reportId].LastRun = DateTime.Now;
            }
        }
Esempio n. 2
0
        private void LoadTree()
        {
            try
            {
                string url = HttpClient.GetUrlFromIp(
                    Settings.Instance.ServerSettings.Server[ServerId].Address,
                    Settings.Instance.ServerSettings.Server[ServerId].Port,
                    Settings.Instance.ServerSettings.Server[ServerId].UseSsl);

                PrtgApiManager api = new PrtgApiManager(
                    url,
                    Settings.Instance.ServerSettings.Server[ServerId].Username,
                    Settings.Instance.ServerSettings.Server[ServerId].Password,
                    true);

                Settings.Instance.SelectedServerSensoorTree =
                    SensorDataXmlParser.ParseSensorTree(HttpClient.GetHttpStream(api.GetSensorTree(), "tree.xml"));
            }
            catch (Exception e)
            {
                ErrorHandler.HandleError(e);
                bw.CancelAsync();
            }
        }
Esempio n. 3
0
 private void run(int reportId)
 {
     string url = HttpClient.GetUrlFromIp(Settings.Instance.ServerSettings.Server[ServerId].Address, Settings.Instance.ServerSettings.Server[ServerId].Port, Settings.Instance.ServerSettings.Server[ServerId].UseSsl);
     PrtgApiManager api = new PrtgApiManager(url, Settings.Instance.ServerSettings.Server[ServerId].Username, Settings.Instance.ServerSettings.Server[ServerId].Password, true);
     SetStatusText("Receiving data from the PRTG server...");
     SensorReport report = Settings.Instance.ServerSettings.Server[ServerId].Groups[GroupId].Reports[reportId];
     string tmpChannelsFile = HttpClient.GetHttpStream(api.GetSensorChannelNames(report.SensorId), "api_channels.xml");
     string tmpDataFile = HttpClient.GetHttpStream(api.GetHistoricSensorData(report.SensorId, report.Average.ToString(), StartDate, EndDate));
     string chartPath = HttpClient.GetHttpStream(api.GetSensorGraph(report.SensorId, report.Average.ToString(), StartDate, EndDate, 850, 270), "chart.png");
     string percentileTmp = string.Empty;
     if (report.HasPercentile)
     {
         percentileTmp = HttpClient.GetHttpStream(api.GetPercentile(report.SensorId, StartDate, EndDate, report.Percentile, report.PercentileMethod, report.PercentileAvg), "percentile.xml");
     }
     SensorData sensor = null;
     if (!bw.CancellationPending)
     {
         SetStatusText("Parsing data...");
         SensorDataXmlParser parser = new SensorDataXmlParser(report.SensorId);
         sensor = parser.parse(tmpChannelsFile, tmpDataFile);
         if (report.HasPercentile)
         {
             parser.ParsePercentile(percentileTmp);
         }
         sensor.chartPath = chartPath;
     }
     if (!bw.CancellationPending)
     {
         SetStatusText("Running script...");
         if (sensor != null)
         {
             ScriptEngine scr = new ScriptEngine(sensor, report.ScriptName, report.TemplateName, reportId, StartDate, EndDate);
             scr.RunScript();
             if (scr.error)
             {
                 bw.CancelAsync();
             }
         }
     }
     if (!bw.CancellationPending)
     {
         SetStatusText("Creating output...");
         Settings.Instance.ServerSettings.Server[ServerId].Groups[GroupId].Reports[reportId].LastRun = DateTime.Now;
     }
 }