Repository: DataDog/datadogpy

Issue:
String decode in dogwrap
**Describe the bug**
The parameters `notify_success`, `notify_warning` and `notify_error` cause the `AttributeError` shown below to be thrown when used.

```
Traceback (most recent call last):
  File "/usr/local/bin/dogwrap", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/datadog/dogshell/wrap.py", line 377, in main
    event_body = build_event_body(cmd, returncode, stdout, stderr, notifications)
  File "/usr/local/lib/python3.7/site-packages/datadog/dogshell/wrap.py", line 209, in build_event_body
    notifications=notifications.decode("utf-8", "replace")
AttributeError: 'str' object has no attribute 'decode'
```

Line 209 attempts to call a decode method on a string. To my knowledge, this method has been removed in python3.

**To Reproduce**
Steps to reproduce the behavior:
1. Install datadog for python3
2. Execute the `dogwrap` command with the `--notify_error` flag set to any string and a command that causes an error
3. Get an exception

**Expected behavior**
The datadog event to be logged with the string specified by `--notify_error` in after `**>>>> NOTIFICATIONS <<<<**`

**Screenshots**
```
$ dogwrap -n "Example Error" -k ${API_KEY} --submit_mode errors --notify_error "test notification" "pwd -h"

Traceback (most recent call last):
  File "/usr/local/bin/dogwrap", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/datadog/dogshell/wrap.py", line 377, in main
    event_body = build_event_body(cmd, returncode, stdout, stderr, notifications)
  File "/usr/local/lib/python3.7/site-packages/datadog/dogshell/wrap.py", line 209, in build_event_body
    notifications=notifications.decode("utf-8", "replace")
AttributeError: 'str' object has no attribute 'decode'
```

**Environment and Versions (please complete the following information):**
```
$ python3 --version
Python 3.7.6
$ dogwrap --version
dogwrap 0.34.1
```


Discussion:

Patch:
diff --git a/datadog/dogshell/wrap.py b/datadog/dogshell/wrap.py
index 022b333..a454d33 100644
--- a/datadog/dogshell/wrap.py
+++ b/datadog/dogshell/wrap.py
@@ -211,8 +211,9 @@ def build_event_body(cmd, returncode, stdout, stderr, notifications):
         )
 
     if notifications:
+        notifications = notifications.decode("utf-8", "replace") if isinstance(notifications, bytes) else notifications
         fmt_notifications = u"**>>>> NOTIFICATIONS <<<<**\n\n {notifications}\n".format(
-            notifications=notifications.decode("utf-8", "replace")
+            notifications=notifications
         )
 
     return \


Test patch:
diff --git a/tests/unit/dogwrap/test_dogwrap.py b/tests/unit/dogwrap/test_dogwrap.py
index e4cd2a3..02341ca 100644
--- a/tests/unit/dogwrap/test_dogwrap.py
+++ b/tests/unit/dogwrap/test_dogwrap.py
@@ -47,6 +47,11 @@ class TestDogwrap(unittest.TestCase):
         event_body = build_event_body(cmd, returncode, stdout, stderr, notifications)
         self.assertEqual(expected_body, event_body)
 
+        # notifications can be unicode already in py3, make sure we don't try decoding
+        notifications = notifications.decode("utf-8", "replace")
+        event_body = build_event_body(cmd, returncode, stdout, stderr, notifications)
+        self.assertEqual(expected_body, event_body)
+
     def test_parse_options(self):
         options, cmd = parse_options([])
         self.assertEqual(cmd, '')