Good day everyone.
In connection with the growing load on one of the company's website, in which I am listed as a system administrator, it was decided to use the Keepalived balancer. I will not dwell on this product, I will describe the problem that has arisen.
The layout comes from gitlaba. In order for the testing department to be aware of what it is testing at all, a file was added to each individual site a long time ago. Normal txt file that was generated during layout. In itself, this file contained information about the current version (brunch, revision, hash of the last commit and a list of the last 300 commits.) That is, thanks to this file, the tester knows what he is testing. It looks like this:
')

Since this file is on all nodes, it was decided to compare the versions on it.
Took 2 nodes with ubuntu. On each keepalived, nginx, php5-fpm. Virtual ip jumps between nodes.
Since I had a blank check for a decision, I chose what the soul is for.
I will not give a lot of code, since I am not a programmer and writing it is not my responsibility.
The solution is as follows:
- bash script to generate the file in the screenshot above;
- go to build web snails and check;
- python for nagios.
The first step was to write a function to get the hash.
func get_release(revall string) (string){ i := strings.Index(revall, "commit ") chars := revall[i:] i = strings.Index(chars, "\n") returned := chars[:i] return returned }
In this block, I, apparently, receive a line of the form “commit 65f58976c71651c91ba641d43930f07a3d55c244” from a text file.
The config and the function of its reading were also added. For dynamism, there may be several configs, reading is a folder in the style of conf.d. Config consisted of the following:
{ "HeaderHost": "somehost.org", "ips": ["192.168.1.1", "192.168.1.2"], "Hostname": ["somehost.org-1", "somehost.org-2"] }
Here, too, everything is clear, since nginx is configured to *: 80, then you can safely fight in the address specified in interfaces with the desired name. Actually, this is also the address in the config and the hostname just for output to the form.
Request function.
func reqrev(urlic string, host string) string { tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } client := &http.Client{Transport: tr} req, _ := http.NewRequest("GET", urlic, nil) req.Host = host resp, _ := client.Do(req) body, _ := ioutil.ReadAll(resp.Body) return string(body) }
The site is a revrayt from http to https. So a piece about ignoring the certificate was added to the function and the connection goes immediately to https. The piece is higher rather than test than combat, so error handling is not taken into account.
In fact, I enforce that this was the first thing done. First of all, the bootstrap template was found and converted to a specific need.
Then there was a set of various functions, structures and templates of html (with which go works, in my opinion, very simple and convenient), to obtain the desired result. In the end, I got something like the following.

Here we see the difference, if there is one. If the last commit is the same - everything is green calm, if not - the colors turn red and at the top of the page it will be written what and where it diverges.
This page has been added to aggregate information.

By clicking on the REV button we get the same text file.

Further, using all the same functions and adding one new one, we hang it on the go-web server via uri / nagios, for example, json.

In this case, our python-script comes at all ready. Here you are in the array we display the checkable sites (the configs of which are in the conf.d folder), the status for nagios (0-OK), and a description. If there are discrepancies in the description, there will be an array of commits and the status will change.
Obviously, it was possible to find a simpler solution and implement, for example, in one python-script, but it was more fun and interesting to do that. If you are interested, I can comb the code and lay out. I beg your pardon for skewing smeared screenshots.