<commit_before>#!/bin/bash

MEMORY_FILE=/tmp/memory.tmp
BREAK_FILE=/tmp/break.tmp
IP_ADDRESS=`hostname -i`
LOG_FILE=/tmp/logging/$IP_ADDRESS.log

if [ "${SERF_EVENT}" = "user" ]; then # Only process user events in here
  read PAYLOAD
  echo $IP_ADDRESS - Received user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  if [ "${SERF_USER_EVENT}" = "TEST_SET_MEMORY" ]; then							# TEST_SET_MEMORY
    echo $IP_ADDRESS - Processing user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
    echo $PAYLOAD > $MEMORY_FILE
    echo $IP_ADDRESS - Processed user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  elif [ "${SERF_USER_EVENT}" = "TEST_BREAK_FILE" ]; then						# TEST_BREAK_FILE
    echo $IP_ADDRESS - Processing user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
    touch $BREAK_FILE
    echo $IP_ADDRESS - Processed user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  elif [ "${SERF_USER_EVENT}" = "TEST_OVERLOADED" ]; then
    echo $IP_ADDRESS - Processing user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
    ./serf event OVERLOADED $IP_ADDRESS
    echo $IP_ADDRESS - Processed user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  else
    echo $IP_ADDRESS - Unknown event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  fi
fi<commit_msg>The agent will now parse the PAYLOAD for a TARGET=CID pair and only act if the agent's own CID matches the target, or if the target is ALL. Also, if no target is specified the handler defaults to ALL.<commit_after>#!/bin/bash

MEMORY_FILE=/tmp/memory.tmp
BREAK_FILE=/tmp/break.tmp
IP_ADDRESS=`hostname -i`
LOG_FILE=/tmp/logging/$IP_ADDRESS.log
read PAYLOAD

LINE=`cat /proc/1/cgroup | tail -n 1`
CID=${LINE: -64}
TARGET_ARGUMENT=`echo $PAYLOAD | grep -o 'TARGET=[^ ]*'`			# Extract the target argument pair from the PAYLOAD

if [ "$TARGET_ARGUMENT" = "" ]; then						# If no target argument we default to ALL
  TARGET_ARGUMENT="TARGET=ALL"
fi

TARGET=`echo $TARGET_ARGUMENT | grep -o '[^=]*$'`               		# Extract the TARGET from the target argument pair
echo "Target is: $TARGET"

if [ "$TARGET" != "ALL" ]; then              					# If the TARGET is not ALL check it against our CID
  if [ "$TARGET" != "$CID" ]; then                              		# If TARGET does not match our CID exit
    echo "Target: $TARGET CID: $CID. No match. Ignoring." >> $LOG_FILE
    exit 0
  else
    echo "Target: $TARGET CID: $CID. Match. Processing." >> $LOG_FILE
  fi
fi

if [ "${SERF_EVENT}" = "user" ]; then # Only process user events in here
  echo $IP_ADDRESS - Received user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  if [ "${SERF_USER_EVENT}" = "TEST_SET_MEMORY" ]; then							# TEST_SET_MEMORY
    echo $IP_ADDRESS - Processing user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
    echo $PAYLOAD > $MEMORY_FILE
    echo $IP_ADDRESS - Processed user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  elif [ "${SERF_USER_EVENT}" = "TEST_BREAK_FILE" ]; then						# TEST_BREAK_FILE
    echo $IP_ADDRESS - Processing user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
    touch $BREAK_FILE
    echo $IP_ADDRESS - Processed user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  elif [ "${SERF_USER_EVENT}" = "TEST_OVERLOADED" ]; then						# TEST_OVERLOADED
    echo $IP_ADDRESS - Processing user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
    ./serf event OVERLOADED $IP_ADDRESS
    echo $IP_ADDRESS - Processed user event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  else
    echo $IP_ADDRESS - Unknown event: ${SERF_USER_EVENT} with payload of $PAYLOAD >> $LOG_FILE
  fi
fi
{'fraction_non_alphanumeric': 0.11455026455026456, 'fraction_numerical': 0.0013227513227513227, 'mean_word_length': 3.8536585365853657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4932104', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1297, 'n_words': 398}