Forum Discussion

Sam_Gendler's avatar
7 years ago

How to auto-install LMI collector on ec2 instance

I'm looking for cloud-init configuration which will get a collector installer URL with my API key, download the installer, and run it. I'll happily take any non cloud-init solution and convert it.  Here's a cut and past of the question I posted at stack overflow.  The impetus behind this is using terraform to manage AWS infrastructure and not wanting to have to roll a custom AMI just to get a collector up and running.   Here's my SO question, which explains what I'm looking for in a bit more detail (https://stackoverflow.com/questions/47167676/how-can-i-download-and-install-logicmonitor-collector-installer-on-ec2-instance )

[quoted question below]

Logicmonitor collector installers must be fetched with a valid token and the installer expires after a period of time. So there's no simple way to pull a collector installer binary onto a new ec2 instance and then run it.

Instead, it is necessary to use a script which uses Logicmonitor's REST API to generate a new collector installer URL, then fetch that and run it immediately. I'm guessing that, since there is a logicmonitor provider in terraform, at least one other person has gone through this process and already has a working script. Frankly, Logicmonitor's docs provide the bulk of it, so it isn't that hard to generate for myself, but if someone out there already has a nice template or module which adds the necessary pieces to an instance's userdata, you'll save me a couple of hours of copypasta and trial and error work. Something that uses cloud-init would be particularly useful, but I can convert. Basic example:

runcmd:
  - export COLLECTOR_URL = `get_collector_url.sh ${api_key} ${other_var} ${yet_another}`
  - curl -o LogicmonitorCollector.bin $COLLECTOR_URL
  - chmod +x LogicmonitorCollector.bin
  - ./LogicmonitorCollector.bin

I can pull the script for get_collector_url.sh out of github or an S3 bucket in an earlier statement easily enough.

This is the kind of thing I'd love to eventually build into a resource in the logicmonitor provider in terraform. I am new to terraform and don't know what is involved in adding a new resource, but this seems like a common need for anyone planning to bring up all of their infrastructure via terraform, since I don't want to have to manually install collectors on the instances terraform will be launching in my mgmt VPC for handling things like bastion duty and monitoring collectors - especially if those instances actually get launched by Amazon as part of an auto-scaling group, so a self-configuring launch configuration for new instances is very desirable, since there's no telling how long it will take before the user data is executed after the launch configuration is updated with new userdata script.

Note - Logicmonitor claims in the docs that the installer binary itself will expire after 2 hours. I've been taking them at their word on that. If what they actually mean it that the token in the installer URL will expire after 2 hours, I could just download the installer once and stick it in an AMI or S3 bucket so that I need never download it again - just change the config to update collector id. But I'm guessing there are reasons their docs don't provide instructions for just pulling the binary once.

An alternative solution would be an AMI based on Amazon Linux with collector already installed, if anyone has such a thing publicly accessible.

2 Replies

Replies have been turned off for this discussion
  • Thanks. I hadn't seen that, but that's pretty much what I ended up implementing - except that I want info about collector id and collector description to be available to the rest of my provisioning system, so I do all the parts other than downloading and running the installer within terraform templates/modules via provisioners and data sources which run local python scripts, and then the id is passed to the ec2 instance, which then runs a script to download the installer for that collector id and runs it.  I'll eventually post a blog entry about it, but I've got too much on my plate to document it in full just yet.