private void FetchHashFromServer()
        {
            string url    = HttpClient.GetUrlFromIp(_server, _port, _useSsl);
            string pwHash = PrtgApiManager.GetPasswordHash(url, _username, _password);

            if (pwHash != null)
            {
                _hash = pwHash;
            }
            else
            {
                bw.CancelAsync();
            }
        }
Esempio n. 2
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. 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;
     }
 }
        private bool CheckVersion()
        {
            string result;

            if (_useHash)
            {
                result = PrtgApiManager.CheckVersion(_server, _port, _useSsl, _username, _password, _useHash);
            }
            else
            {
                result = PrtgApiManager.CheckVersion(_server, _port, _useSsl, _username, _password);
            }
            if (result == "ok")
            {
                return(true);
            }
            ErrorMessage err = new ErrorMessage(result);

            err.ShowDialog();
            err.Dispose();
            return(false);
        }
Esempio n. 5
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. 6
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();
            }
        }