
There is an opinion that the main working quality of a real sysadmin is laziness. When a sysadmin has a server and this server provides a service — usually the admin puts this service on monitoring — in order to know that the service is ok, to find out that the guard-all-lost-all-broke in the number first and sleep peacefully, knowing that if something happens, it will be awakened by an alert, and not the call of the disgruntled boss.
But what about when the server and service are not their own, but others? After all, this situation happens all the time. A typical small organization: one or two sites on a hosting (for which you have to pay on time, and often also monitor whether the tariffs have changed), a pack of domain names (which also need to be paid on time, or you can even lose) then the number of cell phones (for which the balance should be monitored), contracts (and, accordingly, accounting and settlements) with providers of city telephony, with a VOIP-provider, and in the end - just with an Internet provider for the office.
A sysadmin usually does not pay for all of this himself, but he receives mostly reminder letters to replenish the balance and he will be the last to forget if he forgets to remind those who pay. Who among us at least once in his life did not forget to pay for something like that (for example, because the reminder letter got into spam) and remained without communication, without a website, without a domain, without a bonus,
without a salary, without work , etc. and promised solemnly to himself that next time it will be neater.
')
The casket actually opens simply and, one may say, roughly. In almost any monitoring system (tested on Nagios, Zabbix, Remstats, Ganglia, Zenoss - it’s difficult to imagine a system where it wouldn’t exist) it is possible to execute an external program and the result of its execution (exit exit if we collect data “broke-no "Or output to stdout) register as the value of some parameter in the monitoring.
Suppose we have a cell phone connected to, um, let's say MTS - how would we check the balance on this phone, having only the Internet available? Very simple - go to the site mts.ru, we find an
Internet assistant there , we leave from there for a lighter
PDA version :

We have a phone number, but you will need to set a password for this wonderful “Internet Assistant” - we do this by dialing * 111 * 25 # and setting the password. Enter the phone number and password in the form, and, oh miracle, on the next page will be the desired numbers:

Now it remains to teach this simple procedure the server and tell it to repeat it several times a day.
Armed with our favorite tools for analyzing HTML and HTTP traffic, we rather quickly understand that:
- The user opens the login form, they give him a certain cookie - obviously, to identify the session
- The user enters the login (phone number) and password in the form, clicks "Login" - the received cookie and 2 completed form parameters are sent -
username
and password
. - After a system of clever redirects and reverie, the user eventually gets a page with the word “Balance:” and the required figure.
Armed with a wonderful program like wget (suitable for curl, lftp or any similar tool) for sending HTTP requests and a universal line preparation called sed, you can write and debug a script with 3 lines and one function similar to this for two cups of coffee:
request() { wget \ --load-cookies cookies.txt \ --save-cookies cookies.txt \ --keep-session-cookies \ --quiet \ $@ } request -O 1.html \ 'https://ihelper.mts.ru/SELFCAREPDA/Security.mvc/LogOn' request -O 2.html \ --post-data="username=$LOGIN&password=$PASSWORD" \ 'https://ihelper.mts.ru/SELFCAREPDA/Security.mvc/LogOn' sed -ne '/<br\/>:/ { s,.*>\([0-9.]*\)</.*$,\1,; p }' <2.html
It is not very beautiful, it litters temporary files, but it works:
$ LOGIN=9161234567 PASSWORD=012345 ./monitor 1234.56
Now you need to slightly elevate it and can be connected to your favorite monitoring system. The cell phone balance chart will look something like the one shown in the picture that opened the article: slow downs (gradual expenditure of funds on the balance sheet, subscriber charge) and peaks up (balance replenishment - depositing funds).
In such a simple way - in fact, by simulating a person’s actions in entering and reading in the web interface, you can automatically monitor a lot of external services. Here is another, slightly more banal example from another monitoring system, this time - based on Zabbix:

Here you can see the number of days before the end of the paid period at the Internet provider. 5 days before the end of the term, the trigger is triggered and one reminder is sent, in 1 day the second one with a higher priority. The schedule, of course, is more predictable than that of a cell phone balance, but, nevertheless, these reminders on the triggers have more than once saved a large number of nerve cells for me personally.
Aftermath
It so happened that I had to accumulate a non-zero number of such scripts - and I thought - why everyone writes them himself and spends on it every half an hour of his time - why not create some kind of common repository of free software in which such scripts? I searched, maybe something is already there - the closest one I found is the
BalanceRobot project for Android — a program similar in principle (true, proprietary and closed) that monitors the balance of cellular operators — and created
the SPMon project on github .
Right now he knows how to maintain a
relatively modest set of services :
The project structure is very simple: there is a
services
directory, in which there are scripts in different subdirectories (named for the domain name). The scripts are written in the shell, usually consist of 3-4 lines and connect to work the common part, located in the
_spmon_init
file. This file for work can be either in the current directory, or in a directory one level up, or in some public location (in PATH).
There is a simple test infrastructure in the form of one Makefile (which I, unfortunately, cannot share for obvious reasons), which I launch from time to time and it bypasses all the above services, substituting my personal logins and passwords and by the results of its launch I will check that the scripts are still working.
Anyone who has a desire to share with the community ways to monitor some other Internet services - I invite :)
PS Some time ago,
zuskin had already considered the issue of connecting such scripts to Nagios using php scripts. I offer a slightly more general and minimalist solution that likewise connects to Nagios, Zabbix, Remstats, etc.