|
5 | 5 |
|
6 | 6 | import os |
7 | 7 | import sys |
| 8 | +import json |
8 | 9 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..')) |
9 | 10 | from sdcclient import SdcClient |
10 | 11 |
|
11 | 12 | # |
12 | 13 | # Parse arguments |
13 | 14 | # |
14 | | -if len(sys.argv) < 4: |
15 | | - print 'usage: %s <sysdig-token> name description [severity]' % sys.argv[0] |
16 | | - print 'You can find your token at https://app.sysdigcloud.com/#/settings/user' |
| 15 | +if len(sys.argv) < 3: |
| 16 | + print 'usage: %s <sysdig-token> <name> [description] [severity] [scope] [tags]' % sys.argv[0] |
| 17 | + print ' sysdig-token: You can find your token at https://app.sysdigcloud.com/#/settings/user' |
| 18 | + print ' severity: syslog style (from 0 to 7)' |
| 19 | + print ' scope: Sysdig Cloud format metadata to associate with the event, eg: \'host.hostName = "ip-10-1-1-1" and container.name = "foo"\'' |
| 20 | + print ' tags: dictionary of key-value pairs, eg: \'{"app":"my_app", "file":"text.py"}\'' |
17 | 21 | sys.exit(1) |
18 | 22 |
|
19 | 23 | sdc_token = sys.argv[1] |
20 | 24 | name = sys.argv[2] |
21 | | -description = sys.argv[3] |
| 25 | + |
| 26 | +description = '' |
| 27 | +if len(sys.argv) > 3: |
| 28 | + description = sys.argv[3] |
| 29 | +# print description |
22 | 30 |
|
23 | 31 | severity = 6 |
24 | | -if len(sys.argv) < 4: |
| 32 | +if len(sys.argv) > 4: |
25 | 33 | severity = int(sys.argv[4]) |
| 34 | +# print severity |
| 35 | + |
| 36 | +scope = '' |
| 37 | +if len(sys.argv) > 5: |
| 38 | + scope = sys.argv[5] |
| 39 | +# scope = "'host.hostName = 'ip-10-1-1-1'" |
| 40 | +# print scope |
26 | 41 |
|
| 42 | +tags = {} |
| 43 | +if len(sys.argv) > 6: |
| 44 | + tags = json.loads(sys.argv[6]) |
| 45 | +# print json.dumps(tags) |
| 46 | + |
27 | 47 | # |
28 | 48 | # Instantiate the SDC client |
29 | 49 | # |
30 | 50 | sdclient = SdcClient(sdc_token) |
31 | 51 |
|
32 | 52 | # |
33 | | -# Post the event |
| 53 | +# Post the event using post_event(self, name, description=None, severity=6, event_filter=None, tags=None) |
34 | 54 | # |
35 | | -res = sdclient.post_event(name, description, severity, tags={"tag1" : "value1"}) |
| 55 | +res = sdclient.post_event(name, description, severity, scope, tags) |
36 | 56 |
|
37 | 57 | # |
38 | 58 | # Return the result |
|
0 commit comments