Skip to content

Instantly share code, notes, and snippets.

@rdempsey
Created September 28, 2016 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdempsey/a667f3dfa375c56a56907405a0e2aa70 to your computer and use it in GitHub Desktop.
Save rdempsey/a667f3dfa375c56a56907405a0e2aa70 to your computer and use it in GitHub Desktop.
Test collection with a dockerized Traptor
import redis
# Redis connection
redis_conn = redis.StrictRedis(host='localhost',
port=6379,
db=5,
decode_responses=True)
# New rule
new_rule = {
'tag': 'rob.test',
'value': 'python',
'appid': 'rob-test',
'date_added': '2016-09-28 11:26:37',
'description': 'Test rule for python',
'status': 'active',
'rule_type': 'track',
'rule_id': '12345',
'campaign_id': 'test-campaign',
'project_id': 'test-project',
'project_version_id': 'test-project-version-id',
'node_id': 'test-node-id'
}
# Assign the rule to a track traptor with an id of 0
try:
hash_key = 'traptor-track:{}:{}'.format(0, new_rule['rule_id'])
redis_conn.hmset(hash_key, new_rule)
print("Follow rule added to Redis: {} - {}".format(new_rule['rule_id'], hash_key))
except Exception as e:
print("Exception when adding follow rule {}: {}".format(new_rule, e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment