CRAB-21879: Add a tag_instances command to Nagbot#1
CRAB-21879: Add a tag_instances command to Nagbot#1
Conversation
…p_after and terminate_after flags
There was a problem hiding this comment.
Aside from a couple piddling formatting / style comments, I think this looks good! I ran the unit tests and everything passed.
I can break out some time to exploratory test later today or tomorrow, once I make a bit more headway on my STAR week stuff -- how have you been testing this with EC2? I assume the easiest way to do so in isolation would be to spin up a couple free-tier instances on my personal account (?)
app/nagbot.py
Outdated
| if not instance.stop_after: | ||
| sqaws.set_tag(instance.region_name, instance.instance_id, 'Stop after', | ||
| AUTO_STOP_AFTER_DAY_YYYY_MM_DD) | ||
| if (not instance.terminate_after |
There was a problem hiding this comment.
This would be a bit more readable if we pulled out a helper method e.g. _terminate_after_date_present(instance) or something; could also be used by is_taggable()
There was a problem hiding this comment.
Actually, it could be a method on Instance
There was a problem hiding this comment.
I moved is_stop_after_tag_missing and is_terminate_after_tag_missing to Instance. I chose not to pass the whitelist logic into Instance or move other functions like is_stoppable, which would require moving or passing the DateTime constants for now. I would like to do so in the future, but maybe in more of a 0.0.1 pass.
f76c363 to
fa488f8
Compare
That's a great question. Once the code looked good, I was planning on doing something similar to your suggestions - either giving the bot free reign on my personal account with $0 instances or adding custom filter logic before deploying so it could only potentially impact a select few instances. Since this is set up as a whole new top-level arg to be run in its own Cron schedule, it's very easy to test and deploy it independently. (I have no idea how to reply to top-level comments in Github. Hopefully this is how.) |
This adds a new
tag_instancescommand to Nagbot. It's intended to run shortly beforenotifyin the mornings.If
Stop aftertag is not present, it will be set to three days in the future. IfTerminate afteris not set to a valid date, it will be set to two weeks in the future. A slack message will be sent if any instances get new tags added.I hope to extend this new command in the future to parse the instance
Name, look for any known names within Seeq, and automatically add a Contact email. E.G. an instance named "Dak's manual testing" would be able to automatically add my email address as the contact.