{"id":15361,"date":"2014-09-01T13:38:48","date_gmt":"2014-09-01T08:08:48","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=15361"},"modified":"2014-09-01T13:40:39","modified_gmt":"2014-09-01T08:10:39","slug":"alarms-deletion-at-server-termination","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/alarms-deletion-at-server-termination\/","title":{"rendered":"Alarms Deletion at server termination"},"content":{"rendered":"<p>Whenever Autoscaling server terminates it leaves its alarms which later goes into insufficient state. This blog will guide you how to delete all those alarms of autoscaling server when it terminates. In order to do so, I&#8217;ve written a small shell script, I&#8217;m assuming that you already have aws cli installed if not you can <a href=\"http:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/installing.html\">click here<\/a> to follow amazon documentation to install it<\/p>\n<p>[js]#!\/bin\/bash \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ########### she bang<br \/>\nINST_ID=`ec2metadata &#8211;instance-id` \u00a0 \u00a0 ############## to store instance id of a autoscaling server in a variable INST_ID<br \/>\nalarm_name=`aws cloudwatch describe-alarms &#8211;query &#8216;MetricAlarms[*].[Dimensions[0].Value,AlarmName]&#8217; |awk &#8216;\/&#8217;&quot;$INST_ID&quot;&#8217;\/ {print $2}&#8217;` ### to store alarm names that are attached to the server<br \/>\nfor i in `alarm_name`<br \/>\ndo<br \/>\naws cloudwatch delete-alarms &#8211;alarm-names $i \u00a0 \u00a0 \u00a0 \u00a0##### to delete alarms<br \/>\ndone<br \/>\n[\/js]<\/p>\n<p>Now move this script to \/etc\/init.d\/ and create a symbolic link to \/etc\/rc0.d\/. The symlink name should begin with a &#8220;S&#8221; or &#8220;K&#8221;.<br \/>\nFiles that begin with K are run to terminate (kill) a system service. Files that begin with S are run to start a system service.<br \/>\nIf you analyze scripts in \/etc\/rcX.d\/ directory, they starts with &#8220;S&#8221; or &#8220;K&#8221; followed by a number. These numbers decide their priority in which these scripts will run, for example, S23 runs before S34.<\/p>\n<p>I&#8217;ve created a script in \/etc\/init.d\/delete_alarms<\/p>\n<p>and then made its symbolic link in \/etc\/rc0.d\/<\/p>\n<p>ln -s \/etc\/init.d\/delete_alarms \/etc\/rc0.d\/K00delete_alarms<\/p>\n<p>Please pick you priority number carefully as wrong priority number might crash your system and it wont boot again. My script name has started with K00 as autoscaling server has only one life, so I don&#8217;t have to be worried about starting that again<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whenever Autoscaling server terminates it leaves its alarms which later goes into insufficient state. This blog will guide you how to delete all those alarms of autoscaling server when it terminates. In order to do so, I&#8217;ve written a small shell script, I&#8217;m assuming that you already have aws cli installed if not you can [&hellip;]<\/p>\n","protected":false},"author":124,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[1174],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15361"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/124"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=15361"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15361\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=15361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=15361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=15361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}