npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

icinga-aws-autoscaling

v0.4.0

Published

Dynamic management of AWS Auto-Scaling Group inventory in Icinga.

Downloads

15

Readme

icinga-aws-autoscaling

Dynamic management of AWS Auto-Scaling Group inventory in Icinga.

Preparing the code for AWS Lambda

  • Copy ./config.json.example to ./config.json. Replace the settings inside with those applicable to your setup.
    • See the "Config values" section below for more details.
  • Run: rm -rf node_modules && npm install --production
  • Build the Lambda ZIP by running: npm run build
    • This will produce a zip file in the ./build folder for you to upload to AWS Lambda.

Config values

  • icinga_host, icinga_port, icinga_user, and icinga_pass are all required.
  • icinga_host_name_property - Optional, defaults to "instance_id". Determines what to set the name of the host to in Icinga. One of: "instance_id", "public_dns", "public_ip", "private_dns", or "private_ip".
  • icinga_host_vars - Optional. Set to an object where each key is the host var vars.KEY, and each value is the host var's value.
    • EG: "icinga_host_vars": {"os": "Linux"} would set vars.os to "Linux".
    • This is useful for dynamically assigning host groups (see ./examples/icinga_configs/host_group.conf).

AWS Setup

Creating the SNS Topic

  • Enter a topic name and display name.
  • This is how we will feed Auto-Scaling Group scale events into our Lambda function.

Creating the Lambda Function

  • Create a new Lambda function, using the "Blank Function" blueprint.
  • For the trigger, choose "SNS", then choose the SNS topic created earlier.
  • You do not need to enable the trigger yet.
  • Enter a name and description for the function, then choose a runtime of "Node.js 6.10".
  • For the Lambda function code, choose "Upload a .ZIP file", then select the zip of this repo that we created earlier.
  • For the "function handler", enter index.handler
  • For the "function role", you will need to create a new IAM role. Choose "Create a custom role".
    • This will open a new window where you can create a new IAM role.
    • Enter an appropriate Role Name.
    • Edit the Policy Document so that it contains JSON below. It is a combination of the AWSLambdaBasicExecutionRole and AmazonEC2ReadOnlyAccess roles.
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "ec2:Describe*",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "elasticloadbalancing:Describe*",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "cloudwatch:ListMetrics",
        "cloudwatch:GetMetricStatistics",
        "cloudwatch:Describe*"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "autoscaling:Describe*",
      "Resource": "*"
    }
  ]
}
  • Add any tags you need, and change any of the advanced settings you would like to.
    • I have found the default memory and timeout of 128mb and 3sec work fine.
  • Click the Create Function button to finish this step.
  • You should enable this Lambda Function BEFORE you configure your Auto-Scaling Group to publish to the SNS Topic.

Configuring your Auto-Scaling Group to publish to the SNS Topic

  • Go to your ASG, and open the "Notifications" tab.
  • Create a new notification.
  • Select "use existing topic", and select the SNS Topic we created earlier.
  • Select the "Launch" and "Terminate" events. This code does not yet support the other event types ("fail to launch" and "fail to terminate").
  • Save the new notification.

All together now!

  • Create the SNS topic (see above).
  • Create the Lambda Function (see above).
  • Configure your ASG to publish to the SNS Topic (see above).
  • You should now be able to scale your ASG, and see instances added/removed in Icinga 2.

Troubleshooting.

  • The first place to look is the logs for the Lambda Function.
    • Go to Cloudwatch -> Logs. Choose the log group for your Lambda Function.
    • If you do not see any Node.js errors, there is not much I can help with. Check your config, check your security groups, etc.
    • If you DO see Node.js errors, it is likely they are related to the requests sent to Icinga 2. Read them and determine if you have a config or security group issue.
    • Issues with the code in this repo should result in a bug ticket being filed.

Running code locally

  • Install all dependencies using: rm -rf ./node_modules && npm install
  • Open a Node.js REPL using: node
  • You can simulate an ASG Launch/Terminate event using:
let index = require('./index')

const launchEvent = {Records: [{Sns: {Message: "{\"Event\": \"autoscaling:EC2_INSTANCE_LAUNCH\", \"Details\": {\"Availability Zone\": \"us-west-2a\"}, \"EC2InstanceId\": \"i-08fa737d84cf6651b\"}"}}]}
index.handler(launchEvent, {}, function() {});

const terminateEvent = {Records: [{Sns: {Message: "{\"Event\": \"autoscaling:EC2_INSTANCE_TERMINATE\", \"Details\": {\"Availability Zone\": \"us-west-2a\"}, \"EC2InstanceId\": \"i-08fa737d84cf6651b\"}"}}]}
index.handler(terminateEvent, {}, function() {});
  • Don't forget to replace the Availability Zone and EC2 Instance ID.

Running tests

  • Run tests: npm run test
  • Run tests w/ coverage: npm run test:coverage

TODO

  • Add full event payload to fixtures.