Contributing to Go Projects

Contributing to projects on GitHub is a great way to learn, contribute, and help make the software you use better. Normally, you would just make a fork of the project and then clone your fork and do your work. Then you would push to a branch in your fork and open a pull request for that branch. Go is a little different however. Since the imports are specific paths to GitHub/GitLab/etc projects you can’t necessarily just fork the project and do work in your fork....

April 20, 2020 · 2 min · 299 words · John Hooks

Using AlertManager Webhooks

The defacto Alerting tool used with Prometheus is Alertmanager. Prometheus sends a notification to Alertmanager whenever a rule is triggered. Alertmanager then takes that notification and sends it to whatever receiver(s) you have defined in your config. It supports quite a few options: email, hipchat, pagerduty, pushover, slack, opsgenie, victorops, webhook, and wechat. For this post I’m focusing on the webhook receiver. First let’s set up our Alert struct: type Alert struct { Receiver string `json:"receiver"` Status string `json:"status"` Alerts []struct { Status string `json:"status"` Labels struct { Alertname string `json:"alertname"` Service string `json:"service"` Severity string `json:"severity"` } `json:"labels"` Annotations struct { Summary string `json:"summary"` } `json:"annotations"` StartsAt string `json:"startsAt"` EndsAt time....

October 19, 2019 · 3 min · 555 words · John Hooks

Ansible Modules with Go

Since Ansible 2.2 you can use binary applications as modules for Ansible. This means you can write modules in languages other than Python. The downside is that the modules aren’t integrated as well as if they were written in Python with Ansiballz. The binary modules only takes the filename as an argument which is a temporary file containing the JSON data of the modules parameters. I took the boilerplate code that Ansible had here and created a small module to generate a random password....

June 30, 2019 · 3 min · 499 words · John Hooks

Directory Server using Go

I’ve been spending time learning Go and here’s a small utility I wrote that’s similar to Python’s SimpleHTTPServer. This utility just creates a small HTTP server serving the directory you define: package main import ( "log" "net/http" "os" ) func main() { if len(os.Args) < 2 { log.Fatal("You must enter a path") } path := os.Args[1] http.Handle("/", http.FileServer(http.Dir(path))) http.ListenAndServe(":8000", nil) } Then just do: go build main.go ./serve /etc

February 22, 2018 · 1 min · 69 words · John Hooks