Skip to content

Commit d3d62d0

Browse files
authored
Read raw data from file or stdin (#108)
1 parent e9f4898 commit d3d62d0

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

alertaclient/commands/cmd_send.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@
1919
@click.option('--origin', '-O', metavar='ORIGIN', help='Origin of alert in form app/host')
2020
@click.option('--type', metavar='EVENT_TYPE', help='Event type eg. exceptionAlert, performanceAlert, nagiosAlert')
2121
@click.option('--timeout', metavar='EXPIRES', type=int, help='Seconds before an open alert will be expired')
22-
@click.option('--raw-data', metavar='STRING', help='Raw data of orignal alert eg. SNMP trap PDU')
22+
@click.option('--raw-data', metavar='STRING', help='Raw data of orignal alert eg. SNMP trap PDU. \'@\' to read from file, \'-\' to read from stdin')
2323
@click.option('--customer', metavar='STRING', help='Customer (Admin only)')
2424
@click.pass_obj
2525
def cli(obj, resource, event, environment, severity, correlate, service, group, value, text, tags, attributes, origin, type, timeout, raw_data, customer):
2626
"""Send an alert."""
2727
client = obj['client']
28+
29+
# read raw data from file or stdin
30+
if raw_data.startswith('@'):
31+
raw_data_file = raw_data.lstrip('@')
32+
with open(raw_data_file, 'r') as f:
33+
raw_data = f.read()
34+
elif raw_data == '-':
35+
raw_data = sys.stdin.read()
36+
2837
try:
2938
id, alert, message = client.send_alert(
3039
resource=resource,

0 commit comments

Comments
 (0)