Ejemplo n.º 1
0
func parseBash(keeper Keeper, text string, currentNumber uint, currentEvent *HistoryEntry, filter *utils.Regexp,
	historyChan chan *HistoryEntry) (bool, uint, *HistoryEntry) {
	continueToConsume := false
	if bashTimestampRegexp.Match(text) {
		if converted, err := strconv.ParseInt(text[1:], 10, 64); err == nil {
			utils.Logger.WithFields(logrus.Fields{
				"timestamp": converted,
			}).Info("Parse timestamp")
			currentEvent.timestamp = converted
		} else {
			utils.Logger.WithFields(logrus.Fields{
				"text":  text,
				"error": err,
			}).Warn("Cannot parse timestamp")
		}
	} else {
		if filter == nil || filter.Match(text) {
			currentEvent.command = text
			currentEvent.number = currentNumber

			continueToConsume = strings.HasSuffix(text, "\\")
			if !continueToConsume {
				utils.Logger.WithFields(logrus.Fields{
					"event": currentEvent,
				}).Info("Commit event")
				currentEvent = keeper.Commit(currentEvent, historyChan)
			}
		} else {
			utils.Logger.Info("Skip text line because of the filter.")
		}
		currentNumber++
	}

	return continueToConsume, currentNumber, currentEvent
}
Ejemplo n.º 2
0
func parseZsh(keeper Keeper, text string, currentNumber uint, currentEvent *HistoryEntry, filter *utils.Regexp,
	historyChan chan *HistoryEntry) (bool, uint, *HistoryEntry) {
	continueToConsume := false
	groups, err := zshLineRegexp.Groups(text)

	if err != nil {
		utils.Logger.WithFields(logrus.Fields{
			"error": err,
		}).Warn("Cannot parse current line, skip.")
		return continueToConsume, currentNumber, currentEvent
	}
	timestamp, command := groups[0], groups[1]
	currentNumber++

	if filter != nil && !filter.Match(command) {
		utils.Logger.Info("Skip text line because of the filter.")
		return continueToConsume, currentNumber, currentEvent
	}

	converted, _ := strconv.ParseInt(timestamp, 10, 64)
	currentEvent.command = command
	currentEvent.number = currentNumber
	currentEvent.timestamp = converted

	continueToConsume = strings.HasSuffix(text, `\`)
	if !continueToConsume {
		utils.Logger.WithFields(logrus.Fields{
			"event": currentEvent,
		}).Info("Commit event")
		currentEvent = keeper.Commit(currentEvent, historyChan)
	}

	return continueToConsume, currentNumber, currentEvent
}