updateVisualizeTimeWindow = () => {
        const VISUALIZE_TIME_WINDOW_MULTIPLIER = 5;

        const fromExpression = `now-${this.watch.timeWindowSize * VISUALIZE_TIME_WINDOW_MULTIPLIER}${this.watch.timeWindowUnit}`;
        const toExpression = `now`;

        const fromMoment = dateMath.parse(fromExpression);
        const toMoment = dateMath.parse(toExpression);
        this.visualizeTimeWindowFrom = fromMoment ? fromMoment.valueOf() : undefined;
        this.visualizeTimeWindowTo = toMoment ? toMoment.valueOf() : undefined;
      }
  const calcWzInterval = () => {
    let wzInterval = false;
    try {
      const from = dateMath.parse($scope.timefilter.time.from);
      const to   = dateMath.parse($scope.timefilter.time.to);
      
      const totalSeconds = (to - from) / 1000;
      if(totalSeconds <= 3600 )                                 wzInterval = 'm';
      else if(totalSeconds > 3600 && totalSeconds <= 86400)     wzInterval = 'h';
      else if(totalSeconds > 86400 && totalSeconds <= 604800)   wzInterval = 'd';
      else if(totalSeconds > 604800 && totalSeconds <= 2419200) wzInterval = 'w';
      else                                                      wzInterval = 'M';


    } catch (error) {}

    return wzInterval;
  };
  $scope.updateTime = function () {

    ////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////  WAZUH   ///////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    if($location.search().tab != 'configuration') {
      loadedVisualizations.removeAll();
      $rootScope.rendered = false;
      $rootScope.loadingStatus = "Fetching data...";
    }
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////

    $scope.timeRange = {
      from: dateMath.parse(timefilter.time.from),
      to: dateMath.parse(timefilter.time.to, { roundUp: true })
    };
  };
Example #4
0
      function validateDateMath(input) {
        if (input == null || input === '') {
          ngModel.$setValidity('validDateMath', true);
          return null;
        }

        const moment = dateMath.parse(input);
        ngModel.$setValidity('validDateMath', moment != null && moment.isValid());
        return input;
      }
Example #5
0
      $scope.setMode = function (thisMode) {
        switch (thisMode) {
          case TIME_MODES.QUICK:
            break;
          case TIME_MODES.RECENT:
            break;
          case TIME_MODES.RELATIVE:
            $scope.relative = parseRelativeParts($scope.from, $scope.to);
            $scope.formatRelative('from');
            $scope.formatRelative('to');
            break;
          case TIME_MODES.ABSOLUTE:
            $scope.absolute.from = dateMath.parse($scope.from || moment().subtract(15, 'minutes'));
            $scope.absolute.to = dateMath.parse($scope.to || moment(), { roundUp: true });
            break;
        }

        $scope.mode = thisMode;
      };
Example #6
0
function formatTimeString(timeString, dateFormat, roundUp = false) {
  if (moment(timeString).isValid()) {
    return moment(timeString).format(dateFormat);
  } else {
    if (timeString === 'now') {
      return 'now';
    } else {
      const tryParse = dateMath.parse(timeString, { roundUp: roundUp });
      return moment.isMoment(tryParse) ? '~ ' + tryParse.fromNow() : timeString;
    }
  }
}
Example #7
0
 $scope.formatRelative = function (key) {
   const relativeString = getRelativeString(key);
   const parsed = dateMath.parse(relativeString, { roundUp: key === 'to' });
   let preview;
   if (relativeString === 'now') {
     preview = 'Now';
   } else {
     preview = parsed ? parsed.format($scope.format) : undefined;
   }
   _.set($scope, `relative.${key}.preview`, preview);
   return parsed;
 };
    function setTime() {
      $scope.ui.bucketSpanValid = true;
      $scope.formConfig.start = dateMath.parse(timefilter.getTime().from).valueOf();
      $scope.formConfig.end = dateMath.parse(timefilter.getTime().to).valueOf();
      $scope.formConfig.format = 'epoch_millis';

      const bucketSpanInterval = parseInterval($scope.formConfig.bucketSpan);
      if(bucketSpanInterval === null || bucketSpanInterval.asMilliseconds() === 0) {
        $scope.ui.bucketSpanValid = false;
      }

      const bounds = timefilter.getActiveBounds();
      $scope.formConfig.chartInterval = new MlTimeBuckets();
      $scope.formConfig.chartInterval.setBarTarget(BAR_TARGET);
      $scope.formConfig.chartInterval.setMaxBars(MAX_BARS);
      $scope.formConfig.chartInterval.setInterval('auto');
      $scope.formConfig.chartInterval.setBounds(bounds);

      adjustIntervalDisplayed($scope.formConfig);

      $scope.ui.isFormValid();
      $scope.ui.dirty = true;
    }
export function parseRelativeString(part) {
  let results = {};
  const matches = _.isString(part) && part.match(/now(([\-\+])([0-9]+)([smhdwMy])(\/[smhdwMy])?)?/);

  const isNow = matches && !matches[1];
  const opperator = matches && matches[2];
  const count = matches && matches[3];
  const unit = matches && matches[4];
  const roundBy = matches && matches[5];

  if (isNow) {
    return { count: 0, unit: 's', round: false };
  }

  if (count && unit) {
    results.count = parseInt(count, 10);
    results.unit = unit;
    if (opperator === '+') results.unit += '+';
    results.round = roundBy ? true : false;
    return results;

  } else {
    results = { count: 0, unit: 's', round: false };
    const duration = moment.duration(moment().diff(dateMath.parse(part)));
    const units = _.pluck(_.clone(relativeOptions).reverse(), 'value')
      .filter(s => /^[smhdwMy]$/.test(s));
    let unitOp = '';
    for (let i = 0; i < units.length; i++) {
      const as = duration.as(units[i]);
      if (as < 0) unitOp = '+';
      if (Math.abs(as) > 1) {
        results.count = Math.round(Math.abs(as));
        results.unit = units[i] + unitOp;
        results.round = false;
        break;
      }
    }
    return results;
  }


}
Example #10
0
 $scope.updateTime = function () {
   $scope.timeRange = {
     from: dateMath.parse(timefilter.getTime().from),
     to: dateMath.parse(timefilter.getTime().to, { roundUp: true })
   };
 };
Example #11
0
          .then((resp) => {
            if ($scope.formConfig.useFullIndexData) {
              $scope.formConfig.start = resp.start.epoch;
              $scope.formConfig.end = resp.end.epoch;
            } else {
              $scope.formConfig.start = dateMath.parse(timefilter.getTime().from).valueOf();
              $scope.formConfig.end = dateMath.parse(timefilter.getTime().to).valueOf();
            }
            let jobsCounter = 0;
            let datafeedCounter = 0;

            open(jobs[jobsCounter]);

            function incrementAndOpen(job) {
              jobsCounter++;
              if (jobsCounter < numberOfJobs) {
                open(jobs[jobsCounter]);
              } else {
                // if the last job failed, reject out of the function
                // so it can be caught higher up
                if (job.runningState === DATAFEED_STATE.FAILED) {
                  reject();
                }
              }
            }

            function open(job) {
              if (job.jobState === SAVE_STATE.FAILED) {
                // we're skipping over the datafeed, so bump the
                // counter up manually so it all tallies at the end.
                datafeedCounter++;
                job.runningState = DATAFEED_STATE.FAILED;
                incrementAndOpen(job);
                return;
              }
              job.runningState = DATAFEED_STATE.STARTING;
              const jobId = $scope.formConfig.jobLabel + job.id;
              mlJobService.openJob(jobId)
                .then(() => {
                  incrementAndOpen(job);
                  start(job);
                }).catch((err) => {
                  console.log('Opening job failed', err);
                  start(job);
                  job.errors.push(err.message);
                  incrementAndOpen(job);
                });
            }

            function start(job) {
              const jobId = $scope.formConfig.jobLabel + job.id;
              const datafeedId = prefixDatafeedId(job.datafeedId, $scope.formConfig.jobLabel);
              mlCreateRecognizerJobsService.startDatafeed(
                datafeedId,
                jobId,
                $scope.formConfig.start,
                $scope.formConfig.end)
                .then(() => {
                  job.runningState = DATAFEED_STATE.STARTED;
                  datafeedCounter++;
                  if (datafeedCounter === numberOfJobs) {
                    resolve();
                  }
                })
                .catch((err) => {
                  console.log('Starting datafeed failed', err);
                  job.errors.push(err.message);
                  job.runningState = DATAFEED_STATE.FAILED;
                  reject(err);
                });
            }
          });