<commit_before>#!/usr/bin/env python
#
# This script shows how to use the create_alert() call to create the following
# Sysdig Cloud alert: 'send an email notification when the CPU of any tomcat
# process running on any of the instrumented machines goes over 80%'
#
#

import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdcClient

#
# Parse arguments
#
if len(sys.argv) != 2:
    print 'usage: %s <sysdig-token>' % sys.argv[0]
    print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
    sys.exit(1)

sdc_token = sys.argv[1]

#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token)

#
# Find notification channels (you need IDs to create an alert).
#
notify_channels = [ {'type': 'SLACK', 'channel': 'sysdig-demo2-alerts'},
                    {'type': 'EMAIL', 'emailRecipients': ['<EMAIL>']},
                    {'type': 'SNS', 'snsTopicARNs': ['arn:aws:sns:us-east-1:273107874544:alarms-stg']}
                    ]

res = sdclient.get_notification_ids(notify_channels)
if not res[0]:
    print "Could not get IDs and hence not creating the alert: " + res[1]
    sys.exit(-1)

notification_channel_ids = res[1]

#
# Create the alert.
#
res = sdclient.create_alert('tomcat cpu > 80% on any host',  # Alert name.
                            'this alert was automatically created using the python Sysdig Cloud library', # Alert description.
                            6, # Syslog-encoded severity. 6 means 'info'.
                            60, # The alert will fire if the condition is met for at least 60 seconds.
                            'avg(cpu.used.percent) > 80', # The condition.
                            ['host.mac', 'proc.name'], # Segmentation. We want to check this metric for every process on every machine.
                            'ANY', # in case there is more than one tomcat process, this alert will fire when a single one of them crosses the 80% threshold.
                            'proc.name = "tomcat"', # Filter. We want to receive a notification only if the name of the process meeting the condition is 'tomcat'.
                            notification_channel_ids,
                            False) # This alert will be disabled when it's created.

#
# Validate a print the results.
#
print res[1]<commit_msg>Fix failing example. Email addresses did not exist for Notification Channel.<commit_after>#!/usr/bin/env python
#
# This script shows how to use the create_alert() call to create the following
# Sysdig Cloud alert: 'send an email notification when the CPU of any tomcat
# process running on any of the instrumented machines goes over 80%'
#
#

import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdcClient

#
# Parse arguments
#
if len(sys.argv) != 2:
    print 'usage: %s <sysdig-token>' % sys.argv[0]
    print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
    sys.exit(1)

sdc_token = sys.argv[1]

#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token)

#
# Find notification channels (you need IDs to create an alert).
#
notify_channels = [ {'type': 'SLACK', 'channel': 'sysdig-demo2-alerts'},
                    {'type': 'EMAIL', 'emailRecipients': ['<EMAIL>', '<EMAIL>']},
                    {'type': 'SNS', 'snsTopicARNs': ['arn:aws:sns:us-east-1:273107874544:alarms-stg']}
                    ]

res = sdclient.get_notification_ids(notify_channels)
if not res[0]:
    print "Could not get IDs and hence not creating the alert: " + res[1]
    sys.exit(-1)

notification_channel_ids = res[1]

#
# Create the alert.
#
res = sdclient.create_alert('tomcat cpu > 80% on any host',  # Alert name.
                            'this alert was automatically created using the python Sysdig Cloud library', # Alert description.
                            6, # Syslog-encoded severity. 6 means 'info'.
                            60, # The alert will fire if the condition is met for at least 60 seconds.
                            'avg(cpu.used.percent) > 80', # The condition.
                            ['host.mac', 'proc.name'], # Segmentation. We want to check this metric for every process on every machine.
                            'ANY', # in case there is more than one tomcat process, this alert will fire when a single one of them crosses the 80% threshold.
                            'proc.name = "tomcat"', # Filter. We want to receive a notification only if the name of the process meeting the condition is 'tomcat'.
                            notification_channel_ids,
                            False) # This alert will be disabled when it's created.

#
# Validate a print the results.
#
print res[1]
{'fraction_non_alphanumeric': 0.10849645980841316, 'fraction_numerical': 0.01624323198667222, 'mean_word_length': 2.4504310344827585, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4901461', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1373, 'n_words': 502}