Skip to content

Commit d34ccbd

Browse files
committed
post_event.py full args
1 parent 8478ca5 commit d34ccbd

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

examples/post_event.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,54 @@
55

66
import os
77
import sys
8+
import json
89
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
910
from sdcclient import SdcClient
1011

1112
#
1213
# Parse arguments
1314
#
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"}\''
1721
sys.exit(1)
1822

1923
sdc_token = sys.argv[1]
2024
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
2230

2331
severity = 6
24-
if len(sys.argv) < 4:
32+
if len(sys.argv) > 4:
2533
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
2641

42+
tags = {}
43+
if len(sys.argv) > 6:
44+
tags = json.loads(sys.argv[6])
45+
# print json.dumps(tags)
46+
2747
#
2848
# Instantiate the SDC client
2949
#
3050
sdclient = SdcClient(sdc_token)
3151

3252
#
33-
# Post the event
53+
# Post the event using post_event(self, name, description=None, severity=6, event_filter=None, tags=None)
3454
#
35-
res = sdclient.post_event(name, description, severity, tags={"tag1" : "value1"})
55+
res = sdclient.post_event(name, description, severity, scope, tags)
3656

3757
#
3858
# Return the result

0 commit comments

Comments
 (0)