Allow prefix and postfix to have multiple parts.
add a little coverage for none legacy namespaces
use t.eq(...)
Merge pull request #18 from lambdafu/lambdafu/prepostfixparts

Allow prefix and postfix to have multiple parts.
Add collectd tests for all metric types

File /tests/collectd-squares.pkts contains captured collectd
packets containing 4 metrics, one for each type. Each series
has the same 10 measurements with 2 seconds interval. The
values of the measurements are i**2 for i in range(10).

Four test functions have been added to check that the values
of the samples are calculated appropriately for each type.
Fix issue with writing str to file in python 3
Add test for collectd COUNTER wrapping

File /tests/collectd-counter-wrap.pkts contains captured collectd
packets containing 2 sources of type COUNTER. The capture contains
10 measurements with 2 seconds interval for each counter that
increase by 1024 (thus expecting 9 values of 512 when parsed).

One counter wraps around 2^32, the other at 2^64.

The test currently fails because CollectDServer._calc_counter
drops the sample if the value is less than the last one received.

Note: This is required in types.db :
    "counters a:COUNTER:0:U, b:COUNTER:0:U\n"
Fix whitespace issue
Fix handling of collectd counter wrapping

from https://collectd.org/wiki/index.php/Data_source :

COUNTER
These data sources behave exactly like DERIVE data sources in
the “normal” case. Their behavior differs when valuenew < valueold,
i.e. when the new value is smaller than the previous value. In
this case, COUNTER data sources will assume the counter “wrapped
around” and take this into account. The formula for wrap-around
cases is:

rate = (2^width + val - pval) / (time - ptime)
width = pval < 2^32 ? 32 : 64
Add tests for min/max values in collectd samples

Test that values outside the range defined in types.db are dropped
for all basic collectd types.

These tests currently fail. Even though CollectDTypes parses and
stores the min/max values for each type, the sample's value isn't
checked against those limits.
Collectd types bounds checking

Add a check_range method to CollectDServer to check that the
values fall within the permitted range as defined in types.db.
Fix whitespace issue
Merge pull request #36 from dimrozakis/collectd_bounds

Collectd: Check value ranges according to types.db
Merge pull request #37 from dimrozakis/collectd_counter_wrap

Collectd: Handle counter wrapping
CollectDCrypto: Skeleton class

CollectDCrypto will handle all signed/encrypted communication
for collectd. Packets are sent to CollectDCrypto where they are
parsed, decrypted or verified and dropped or have their payload
forwarded to CollectDParser according to the security policy.

Two new configuration options are added:
 - collectd_security_level: 0 (default), 1 or 'Sign', 2 or 'Encrypt'
 - collectd_auth_file: The location of the file used to verify
   decrypt the packets.
similar to the 'SecurityLevel' and 'AuthFile' options of collectd's
network plugin.

CollectDCrypto requires PyCrypto.

Possible interactions of client and server security settings
are as described in:
https://collectd.org/wiki/index.php/Networking_introduction#Possible_interactions
CollectDCrypto: Signed pkt parsing (HMAC-SHA256)

- First 2 bytes is the part type. Signed parts have a type of 0x0200.
- Next 2 bytes specify the part's length.
- Next 32 bytes are an HMAC-SHA256 tag on all the bytes following
  the tag.
- Next (part_len - 36) bytes are the username.
- Payload to forward is all bytes after username.

(The hmac is on the username + payload)
CollectDCrypto: Encrypted pkt parsing (AES256)

- First 2 bytes is the part type. For encrypted parts it's 0x0210.
- Next 2 bytes specify the part length.
- Next 2 bytes specify the username length.
- Next uname_len bytes are the username.
- Next 16 bytes are the initialization vector (iv).
- Remaining bytes are the ciphertext. It needs to be padded to a
  multiple of 16 before decryption and unpadded afterwards
  (OFB mode turns AES into a stream cipher).
- The user's password is hashed with SHA256 to produce the
  encryption key.
- Ciphertext is decrypted with AES using the key and iv from above.
- First 20 bytes in the plaintext (padding removed) is a SHA1 hash
  of the remaining bytes of the plaintext.
- Remaining bytes (without the SHA1 tag) are the payload to forward.
CollectDCrypto: Basic test for signing
CollectDCrypto: Basic test for encryption
CollectDCrypto: hashlib & hmac replace Crypto.Hash

Quick tests showed that the functions from hashlib and hmac
were faster than the ones provided by Crypto.Hash

This way, CollectDCrypto's parsing of signed packets doesn't
require PyCrypto.

For encryption, PyCrypto is still required to use AES.