Quote
"Program to create create Network Alarms which are platform specific – using lambda python"

In this article, I have given a code which can be used as reference while writing a program to create Network Alarms which are platform specific – using lambda python

#Create Network Alarms which are platform specific
print (instance.platform)
if (instance.platform != 'windows'):
#ImageId, InstanceId, InstanceType
response = cw.list_metrics(
Namespace='CWAgent',
MetricName='netstat_tcp_established',
Dimensions=[
{
'Name': 'InstanceId',
'Value': instanceid
},
]
#NextToken='string'
)
for metric in response['Metrics']:
###############################################
#Create Netstat TCP Established Connection Alarms
severity = "Warning"
alarm_title = "Linux_netstat_TCP_Established"
response = cw.put_metric_alarm(
AlarmName = "%s_%s_%s_(Lambda)" % (severity, nameinstance, alarm_title),
AlarmDescription='Netstat TCP Established Connections',
ActionsEnabled=True,
AlarmActions=[ec2_sns,],
MetricName='netstat_tcp_established',
Namespace='CWAgent',
Statistic='Average',
Dimensions=[ {'Name': "InstanceId", 'Value': instanceid},
{'Name': 'ImageId', 'Value': instance.image_id},
{'Name': 'InstanceType', 'Value': instance.instance_type}
],
Period=60,
EvaluationPeriods=3,
Threshold=200.0,
ComparisonOperator='GreaterThanOrEqualToThreshold'
)
if logging_verbosity > 9:
print (response)

###############################################
#Create Netstat TCP Time Wait Alarms
severity = "Warning"
alarm_title = "Linux_netstat_TCP_Time_Wait"
response = cw.put_metric_alarm(
AlarmName = "%s_%s_%s_(Lambda)" % (severity, nameinstance, alarm_title),
AlarmDescription='Netstat TCP Established Connections',
ActionsEnabled=True,
AlarmActions=[ec2_sns,],
MetricName='netstat_tcp_time_wait',
Namespace='CWAgent',
Statistic='Average',
Dimensions=[ {'Name': "InstanceId", 'Value': instanceid},
{'Name': 'ImageId', 'Value': instance.image_id},
{'Name': 'InstanceType', 'Value': instance.instance_type}
],
Period=60,
EvaluationPeriods=3,
Threshold=400.0,
ComparisonOperator='GreaterThanOrEqualToThreshold'
)
if logging_verbosity > 9:
print (response)

elif (instance.platform == 'windows'):
#ImageId, InstanceId, InstanceType

###############################################
#Create Windows TCPv4 Established Connection Alarms
severity = "Warning"
alarm_title = "Windows_netstat_TCP_Established"
response = cw.put_metric_alarm(
AlarmName = "%s_%s_%s_(Lambda)" % (severity, nameinstance, alarm_title),
AlarmDescription='Netstat TCP Established Connections',
ActionsEnabled=True,
AlarmActions=[ec2_sns,],
MetricName='TCPv4 Connections Established',
Namespace='CWAgent',
Statistic='Average',
Dimensions=[ {'Name': "InstanceId", 'Value': instanceid},
{'Name': 'ImageId', 'Value': instance.image_id},
{'Name': 'objectname', 'Value': 'TCPv4'},
{'Name': 'InstanceType', 'Value': instance.instance_type}
],
Period=60,
EvaluationPeriods=3,
Threshold=400.0,
ComparisonOperator='GreaterThanOrEqualToThreshold'
)
if logging_verbosity > 9:
print (response)

“If you are passionate about technology and like to share your knowledge or the latest on technology, mail us on info@saniconservices.com and get featured on our blog page”

I hope you find this program useful to create Network Alarms which are platform specific – using lambda python. Feel free to ask your valuable questions in the comments section below.

About SANICON IT SERVICES PVT. LTD.: Over the years SANICON – A One-Stop Cloud Solution Company have provided the most credible cutting-edge IT technology & services across various domains which helped customers around the world to start and grow their businesses and their digital transformation to cloud.

Reach out to us today at sales@saniconservices.com to get a reliable and affordable cloud managed service and IT technology partner

Visit website www.saniconservices.com to learn more about all great products and services offered.

Leave a Reply

Your email address will not be published. Required fields are marked *