It was a simple request at the Weekly Company Meeting: “Can we monitor the number of SMTP (Simple Mail Transport Protocol) connections to our mail servers, and have it graphed in Cacti [1]?” Breaking it down, the answer appears to be yes, and I have no XXXXXXX clue.”
And that is bugging the XXXX out of me.
The first bit? Pretty easy actually.
By default, our servers are already tracking SMTP connections via iptables, and it's a simple matter to pull the number out:
>
```
iptables --list -vnx \
| grep 'state NEW tcp dpt:25' \
| awk '{print $1}'
```
Print the current state of iptables, pull out the line accepting incoming connections to the SMTP port, and print the first column, which is the number of packets (and thus, the number of connections).
Next up is to deliver this information via SNMP (Simple Network Management Protocol). We're using net-snmp [2] and it indeed, does make it easy to export information via SNMP. Take the above command, place it into a file (thus making it a shell script). Then, in the SNMP configuration file:
>
```
exec .1.3.6.1.4.1.2021.9004 snmp_connection /root/bin/smpt_connection
```
Restart the SNMP server, and do your query:
>
```
GenericUnixPrompt> snmpwalk XXXXXXXXXXXXXXXXXX .1.3.6.1.4.1.2021.9004
UCD-SNMP-MIB::ucdavis.9004.1.1 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.9004.2.1 = STRING: "snmp_connection"
UCD-SNMP-MIB::ucdavis.9004.3.1 = STRING: "/root/bin/snmp_connection"
UCD-SNMP-MIB::ucdavis.9004.100.1 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.9004.101.1 = STRING: "62191"
UCD-SNMP-MIB::ucdavis.9004.102.1 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.9004.103.1 = ""
GenericUnixPrompt>
```
So okay, the value we want is a string, and not numeric, but at least we can query it.
Now we get to Cacti.
Eight hours later and I've yet to get a graph out of Cacti.
I found a page that describes a similar setup [3], but check out section 3C and the XML (eXtensible Markup Language) file that's created.
Now check out the SNMP Query XML Syntax [4] for Cacti.
I don't fault you for feeling confused. I'm a XXXXXXXXXX programmer who writes CGI (Common Gateway Interface)s in C for fun [5], and I got horribly confused.
I can't quite figure out how Cacti works. Oh sure, it's easy to install, and monitoring devices isn't all that difficult (I find it rather randomly clunky myself) but adding a new query to Cacti?
If there's a straightforward way of doing that, I haven't found it.
Somehow “Data Queries” are tied to the “Data Templates” although what that connection is eludes me. It seems like you can specify a single SNMP query in a “Data Template” but maybe not, because why have an XML file for the SNMP query?
And the “Graph Templates” tie into this mess as well, although I'm still puzzled at that one.
And the flow is weird—I'll be in the “Data Query” section, obstensibly making a change to a “Data Query” and suddenly find myself in the “Data Template” area after saving a change. Or sometimes in the “Graph Template” area.
Never the “Host Template” area though.
I'm finding it a horribly confusing process and it's bugging me that I can't figure this out. I want to quit and say to Smirk, “Sorry, not possible,” and that is bugging me, because I know it is possible, probably even with Cacti if I just knew what to do.
I know what the problem is—my mental model of how this is supposed to work doesn't match the mental model of the Cacti developers. And without that clear mental model, the whole process under Cacti just doesn't make sense to me.
I had the same problem with C when I first started using it. I had been programming for years in Assembly, and there were certain cases where a problem would have been trivial in Assembly but I was utterly lost for a solution with C. Of course, over time, I gained the ability to “think” in C, and now what was once problematic in C (but not in Assembly) is now trivial in C.
But that took a few years though, and at least with C, the knowledge is still useful. I'm doubting that the time I spend with Cacti will have the same benefit over the long term.
And that's bugging me too, mainly because it seems like I'm justifying not learning it at all.
[2] http://net-snmp.sourceforge.net/
[3] http://www.roth.lu/cacti-snmp-tut.htm
[4] http://www.cacti.net/downloads/docs/html/snmp_query_xml.html