Skip to content

Instantly share code, notes, and snippets.

@koemu
Created July 31, 2014 10:19
Show Gist options
  • Save koemu/73c359f21c6305791d38 to your computer and use it in GitHub Desktop.
Save koemu/73c359f21c6305791d38 to your computer and use it in GitHub Desktop.
Replace hash value for Cacti template xml file.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
import hashlib
source = open( sys.argv[1] ).read()
result = re.finditer( r'hash\_([0-9]{6})(\w{32})', source )
for match in result:
before = "hash_%s%s" % ( match.group(1), match.group(2) )
after = "hash_%s%s" % ( match.group(1), hashlib.md5( match.group(2) ).hexdigest() )
sys.stderr.write( "before: %s, after: %s\n" % ( before, after ) )
source = source.replace( before, after )
print source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment