export default function fetch(method, url, body) {
  const promise = () => new Builder(method, url)
    .authenticated()
    .json(body)
    .build();

  const SessionStore = StoreProvider.getStore('Session');

  if (!SessionStore.isLoggedIn()) {
    return new Promise((resolve, reject) => {
      SessionActions.login.completed.listen(() => {
        promise().then(resolve, reject);
      });
    });
  }
  return promise();
}
      }, (error) => {
        const SessionStore = StoreProvider.getStore('Session');
        if (SessionStore.isLoggedIn() && error.status === 401) {
          SessionActions.logout(SessionStore.getSessionId());
        }

        // Redirect to the start page if a user is logged in but not allowed to access a certain HTTP API.
        if (SessionStore.isLoggedIn() && error.status === 403) {
          history.replaceState(null, Routes.STARTPAGE);
        }

        if (error.originalError && !error.originalError.status) {
          ServerAvailabilityActions.reportError(error);
        }

        throw new FetchError(error.statusText, error);
      });
export function fetchPlainText(method, url, body) {
  const promise = () => new Builder(method, url)
    .authenticated()
    .plaintext(body)
    .build();

  const SessionStore = StoreProvider.getStore('Session');

  if (!SessionStore.isLoggedIn()) {
    return new BluebirdPromise((resolve, reject) => {
      const SessionActions = ActionsProvider.getActions('Session');
      SessionActions.login.completed.listen(() => {
        promise().then(resolve, reject);
      });
    });
  }
  return promise();
}
import Reflux from 'reflux';

import URLUtils from 'util/URLUtils';
import ApiRoutes from 'routing/ApiRoutes';
import fetch, { Builder, fetchPeriodically } from 'logic/rest/FetchProvider';
import TimeHelper from 'util/TimeHelper';

import StoreProvider from 'injection/StoreProvider';
const SessionStore = StoreProvider.getStore('Session');
const NodesStore = StoreProvider.getStore('Nodes');

import ActionsProvider from 'injection/ActionsProvider';
const SessionActions = ActionsProvider.getActions('Session');
const MetricsActions = ActionsProvider.getActions('Metrics');

const MetricsStore = Reflux.createStore({
  listenables: [MetricsActions, SessionActions],
  namespace: 'org',
  registrations: {},
  globalRegistrations: {},
  promises: {},

  init() {
    this.listenTo(NodesStore, this.updateNodes);
  },
  getInitialState() {
    return { metricsNames: this.metricsNames, metrics: this.metrics };
  },
  updateNodes(update) {
    this.nodes = update.nodes;
  },
  authenticated() {
    const SessionStore = StoreProvider.getStore('Session');
    const token = SessionStore.getSessionId();

    return this.session(token);
  }
import ActionsProvider from 'injection/ActionsProvider';

import StoreProvider from 'injection/StoreProvider';

import DateTime from 'logic/datetimes/DateTime';

const AlertsActions = ActionsProvider.getActions('Alerts');
const StreamsStore = StoreProvider.getStore('Streams');

const AlertsAnnotator = {
  streams: [],

  initialize() {
    StreamsStore.listStreams().then((streams) => {
      this.streams = streams;
    });
  },

  fillAlertAnnotator(histogramData, stream, rickshawAnnotator, callback) {
    if (!histogramData || !histogramData[0] || !histogramData[0].x) {
      return;
    }

    const earliestDataPoint = histogramData[0].x;

    let promise;
    if (stream) {
      promise = AlertsActions.list.triggerPromise(stream, earliestDataPoint);
    } else {
      promise = AlertsActions.listAllStreams.triggerPromise(earliestDataPoint);
    }
Example #7
0
import Rickshaw from 'rickshaw';
import Graylog2Time from 'legacy/Rickshaw.Fixtures.Graylog2Time';
import Graylog2Selector from 'legacy/Rickshaw.Graph.Graylog2Selector';

import DateTime from 'logic/datetimes/DateTime';
import GraphVisualization from 'components/visualizations/GraphVisualization';
import URLUtils from 'util/URLUtils';
import fetch from 'logic/rest/FetchProvider';
import ApiRoutes from 'routing/ApiRoutes';
import UserNotification from 'util/UserNotification';
import StringUtils from 'util/StringUtils';
import HistogramFormatter from 'logic/graphs/HistogramFormatter';

import StoreProvider from 'injection/StoreProvider';

const SearchStore = StoreProvider.getStore('Search');

function generateShortId() {
  return Math.random().toString(36).substr(2, 9);
}

export function generateId() {
  let r = '';
  for (let i = 0; i < 4; i++) {
    r += generateShortId();
  }

  return r;
}

function sendFailureEvent(graphId, errorMessage) {
import ActionsProvider from 'injection/ActionsProvider';
const AlertsActions = ActionsProvider.getActions('Alerts');

import StoreProvider from 'injection/StoreProvider';
const AlertsStore = StoreProvider.getStore('Alerts');
const StreamsStore = StoreProvider.getStore('Streams');

import DateTime from 'logic/datetimes/DateTime';

const AlertsAnnotator = {
  streams: [],

  initialize() {
    StreamsStore.listStreams().then(streams => {
      this.streams = streams;
    });
  },

  fillAlertAnnotator(histogramData, stream, rickshawAnnotator, callback) {
    if (!histogramData || !histogramData[0] || !histogramData[0].x) {
      return;
    }

    const earliestDataPoint = histogramData[0].x;

    let promise;
    if (stream) {
      promise = AlertsActions.list.triggerPromise(stream, earliestDataPoint);
    } else {
      promise = AlertsActions.listAllStreams.triggerPromise(earliestDataPoint);
    }
import Reflux from 'reflux';

import StoreProvider from 'injection/StoreProvider';
const MetricsStore = StoreProvider.getStore('Metrics');

import ActionsProvider from 'injection/ActionsProvider';
const MetricsActions = ActionsProvider.getActions('Metrics');

const GlobalThroughputStore = Reflux.createStore({
  listenables: [],
  metrics: {
    input: 'org.graylog2.throughput.input.1-sec-rate',
    output: 'org.graylog2.throughput.output.1-sec-rate',
  },

  init() {
    MetricsActions.addGlobal(this.metrics.input);
    MetricsActions.addGlobal(this.metrics.output);
    this.listenTo(MetricsStore, this.updateMetrics);
    setInterval(MetricsActions.list, this.INTERVAL);
  },
  INTERVAL: 2000,
  updateMetrics(update) {
    if (!update.metrics) {
      return;
    }
    const throughput = {
      input: 0,
      output: 0,
    };
    Object.keys(update.metrics).forEach((nodeId) => {