Use Oomnitza workflows to complete actions in Amazon EC2 such as retrieving the average CPU load and instance status, and starting, stopping, and rebooting instances. Surface key information in operational dashboards and create scheduled reports to share knowledge with your colleagues.
Before you start
1. Your AWS credentials
Before you can create the integration with Oomnitza, you need to add your AWS Access keys to Oomnitza. See Adding your AWS credentials to Oomnitza.
Important
These workflows are not enabled for cross-account access. This means that the credentials that you create must be within the same account the EC2 instance is located. The following permissions were used to query EC2 instances: ReadOnlyAccess (worked successfully on fetch operations such as getting a tag from an EC2 instance) and AmazonEC2FullAccess (used for all other actions, such as creating a new tag or deleting a tag from EC2 instance). See AWS EC2 Identify and access management.
2. Field mappings
All of the following API presets assume that you have created standard field mappings as follows:
- AWS Instance field is mapped to the Oomnitza asset field Serial Number
- AWS Region field is mapped to the custom Oomnitza asset field AWS Region
Creating the workflow
To create a workflow, you must complete these steps:
- Click Configuration > Workflows.
- Click Add
and select Assets from the Objects list.
- Edit the Begin Block and add rules to trigger the workflow.
- Click Edit on the API block and enter EC2 in the search field.
- Select a preset from the list below.
- Amazon AWS EC2 start EC2 instance
- Amazon AWS EC2 stop EC2 instance
- Amazon AWS EC2 reboot EC2 instance
- Amazon AWS get details of single EC2 instance
- Amazon AWS get instance status from EC2
- Amazon AWS create tag for EC2 instance
- Amazon AWS get tag from EC2 instance
- Amazon AWS delete tag from EC2 instance
- Amazon AWS get average CPU Load
- Select your AWS credentials.
- Enter any mandatory information when prompted.
- Select Advanced Mode and review the information in the Information and Body tab. You can map the API response in the Response tab.
- Connect the Blocks.
- Save, validate, and activate your workflow.
Creating workflows
Amazon AWS EC2 start EC2 instance
This Amazon AWS EC2 Start EC2 instance preset allows you to start an existing EC2 instance.
This preset requires the AWS fields Region and Instance ID to be mapped to the Oomnitza fields AWS Region and Serial Number, respectively.
- In the API block window, click Advanced Mode located in the upper right of the window.
- Select the Information tab. The AWS Region is referenced in the property
{{aws_region}}. - Select the Params tab. The Serial Number is referenced in the property
{{serial_number}}. - You can map the entire response by placing
{{response}}in the Response field and mapping it to a custom long text Oomnitza field, such as API Response. Once you have the entire response, you can then parse the JSON response values to custom Oomnitza fields.
Fig 2: Mapping an API response in the API block
Amazon AWS EC2 stop EC2 instance
This Amazon AWS EC2 Stop EC2 instance preset allows you to stop an already existing EC2 instance. You can configure the message payload as per the example in the Amazon AWS EC2 Start EC2 instance also apply to this preset.
Amazon AWS EC2 reboot EC2 instance
This Amazon AWS EC2 Reboot EC2 instance reboot preset allows you to reboot an already existing EC2 instance. You can configure the message payload as per the example in the Amazon AWS EC2 Start EC2 instance also apply to this preset.
Amazon AWS get details of single EC2 instance
This Amazon AWS get details of single EC2 instance preset allows you to get the details of a single EC2 instance. By using this preset, and updating the following in the Response section, you can get the values from the response and parse them to attributes of your Asset in Oomnitza. To do this, complete the following steps:
- In the API block window, click Advanced Mode located in the upper right of the window.
- Ensure that the fields AWS Region and Serial Number are defined within Oomnitza, as mentioned in Amazon AWS EC2 Start EC2 instance.
- Select the Response tab.
- Enter the below code snippet in the Response field and map to an Oomnitza field, such as Instance State.
{% set temp = response['DescribeInstancesResponse']['reservationSet']['item']['instancesSet']['item']['instanceState']['name'] %}{% if 'name' in temp %}{{[temp]}}{% else %}{{temp}}{% endif %}
The above response provides you with the state of the EC2 instance, such as Running or Stopped. When developing your own response mapping, it is a good idea to look at the complete response by parsing it into a long text attribute as per the example in the Amazon AWS EC2 Start EC2 instance. In this way, finding the proper statement will be much easier.
Amazon AWS get instance status from EC2
The Amazon AWS get instance status from EC2 preset allows you to retrieve the status of your EC2 instances. By using this preset, and updating the following in the Response section, you can pull EC2 system status into the mapped field in Oomnitza. To do this, complete the following steps:
- In the API block window, click Advanced Mode located in the upper right of the window.
- Ensure that the fields AWS Region and Serial Number are defined within Oomnitza, as mentioned in Amazon AWS EC2 Start EC2 instance.
- Select the Response tab.
- Enter the below code snippet in the Response field and map to an Oomnitza field, such as Instance Status.
{% if response['DescribeInstanceStatusResponse']['instanceStatusSet'] %} {% set instanceState = response['DescribeInstanceStatusResponse']['instanceStatusSet']['item']['instanceStatus']['status']%} {% set systemStatus = response['DescribeInstanceStatusResponse']['instanceStatusSet']['item']['systemStatus']['status']%} {% if instanceState == 'ok' and systemStatus == 'ok' %} 2/2 check passed {% elif systemStatus == 'not-applicable' %} {% else %} {{systemStatus}} {% endif %} {% else %} {% endif %}
Tagging an instance
Within AWS you have the option to tag resources. Tagging in this case means a name/value pair that allows you to store any information. You can store up to 50 tags per resource in AWS. To enable tagging from within Oomnitza, you need to identify which attributes you should map from Oomnitza to tags in AWS. One possible example would be to map a dropdown list in Oomnitza called Usage with values Customer, Internal, DevOps, Development and Testing to a tag in AWS. There are four sample presets that you can use to tag an EC2 instance.
Amazon AWS create tag for EC2 instance
This Amazon AWS create tag for EC2 instance allows you to create and update tags in AWS from Oomnitza. When you specify an existing tag, the value is overwritten with the new value. To leverage this preset, complete the following steps:
- In the API block window, click Advanced Mode located in the upper right of the window.
- Ensure that the fields AWS Region and Serial Number are defined within Oomnitza, as mentioned in Amazon AWS EC2 Start EC2 instance.
- Select the Params tab.
- By default, Tag.1.Key and Tag.1.Value have already been mapped.
- To add new tags, enter a new key name and value, i.e. Tag.2.Key and Tag.2.Value. Tag.2.Value should be an existing field in Oomnitza, like {{aws_instance_usage}}. In general, we recommend this field to be a drop-down field.
Amazon AWS get tag from EC2 instance
This Amazon AWS get tag from EC2 instance preset allows you to read the tags from AWS instance and store them in an attribute. The API provides a list of tags that you can store in a dropdown list Oomnitza. Alternatively, you can store all tags in a text field in Oomnitza.
To leverage this preset, complete the following steps:
- In the API block window, click Advanced Mode located in the upper right of the window.
- Ensure that the fields AWS Region and Serial Number are defined within Oomnitza, as mentioned in Amazon AWS EC2 Start EC2 instance.
- Select the Response tab.
- Enter the below code snippet in the Response field and map to an Oomnitza field, such as AWS Instance Usage.
{% set temp = response['DescribeTagsResponse']['tagSet']['item']%}{%if (temp is defined) and temp%}{{ temp | selectattr('key', 'eq', 'Usage') | map(attribute='value') | join('') }}{% endif %}
This statement will filter and return values relating to the Usage tag, which you can then pass on to an attribute in Oomnitza like aws_instance_usage.
Using this approach you would have to specify one response mapping for each tag you want to map to Oomnitza. If you map tags to a dropdown list with value list, you should make sure that all these values exist in Oomnitza or alternatively switch this attribute to free text or a dropdown without value list. You could use this preset daily to sync data between AWS and Oomnitza and read all current tags from AWS.
Amazon AWS delete tag from EC2 instance
This Amazon AWS delete tag from EC2 instance preset allows you to delete tags from EC2 instances. In order to remove tags, you must have the Tag Key of the tag you wish to delete, either taken directly from AWS, or using either of the above workflows. To set your workflow to delete a specific tag, apply the Amazon AWS delete tag from EC2 instance to your API block, then complete the following steps:
- In the API block window, click Advanced Mode located in the upper right of the window.
- Ensure that the fields AWS Region and Serial Number are defined within Oomnitza, as mentioned in Amazon AWS EC2 Start EC2 instance.
-
Navigate to the Params tab. From there, specify the tag to delete in the "Tag.1.Key" value field, for example:
Tag.1.Key = stackAlternatively, you can set the param to reference a metadata field in Oomnitza, such as:Tag.1.Key = {{tag_1_key}}
Amazon AWS get average CPU Load
This Amazon AWS get average CPU Load for an EC2 instance preset allows you to get the average CPU Load during a specified monitoring period. You can define the length of the monitoring period in hours and define the number of monitoring periods.
To leverage this preset, complete the following steps:
- In the API block window, click Advanced Mode located in the upper right of the window.
- Ensure that the fields AWS Region and Serial Number are defined within Oomnitza, as mentioned in Amazon AWS EC2 Start EC2 instance.
- Select the Response tab. Map the response to an Oomnitza field, such as Average CPU Load, or Maximum Average CPU Load for a 12h period.
The response mapping will return the average CPU utilization for each specified monitoring period of the EC2 instance, continuing until the total number of monitoring periods is reached. For instance, if your monitoring period is set to 12 hours, and you've specified 14 monitoring periods, you will receive data on the average CPU load for every 12-hour interval across a total duration of 168 hours (or one week). The response can be mapped to show the maximum average CPU load during each 12-hour period. This detailed information can be instrumental in cost optimization. For example, discovering that the maximum average CPU utilization of an instance is consistently below 10% might indicate that the instance is underutilized, prompting a review of its necessity or re-configuration.
Note
This preset uses the AWS CloudWatch monitoring API. Ensure that AWS CloudWatch is enabled and properly configured for your AWS resource. There may be additional charges for using this API within AWS. Please contact AWS for details on this.
Additional instance operations
There are plenty of additional actions available to control your EC2 instances. You can find a complete list at Amazon Elastic Cloud API Reference. We will continue to add the most valuable ones as presets, but for now, you can always start with any of the existing presets and go to Advanced Mode to easily change it to any of the supported actions by AWS.
Comments
0 comments
Please sign in to leave a comment.