exim, perl and snmp! oh my! ian norton shadowcat - agaton
TRANSCRIPT
![Page 1: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/1.jpg)
Exim, Perl and SNMP!Oh my!
Ian NortonShadowcat Systems Ltd.
![Page 2: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/2.jpg)
Exim, Perl and SNMP!Oh my!
Working with Net SNMP Extend.
Ian NortonShadowcat Systems Ltd.
![Page 3: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/3.jpg)
![Page 4: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/4.jpg)
What's this talk about?
● Using Net SNMP extend● Monitoring arbitrary things● Using Exim as an example● Cleverness with OpenNMS
![Page 5: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/5.jpg)
Email systems are evil.
![Page 6: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/6.jpg)
Email systems are evil.
Exim is less evil :)
![Page 7: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/7.jpg)
Exim
● Open source● Mail Transport Agent (MTA)● Mail Delivery Agent (MDA)● Cambridge University
![Page 8: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/8.jpg)
In a previous life....
![Page 10: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/10.jpg)
University infrastructure
InternetHub1
Hub1Hub1
Hub1Hub1
Exchange
Unixmail
Dept 1 Dept 2
![Page 11: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/11.jpg)
Standard service monitoring
● Connect TCP port 25● Check banner● How long did it take?
![Page 12: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/12.jpg)
And so it begins...
● Messages delayed● 4xx temporary failures● Badly behaved senders don't retry
![Page 13: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/13.jpg)
Everything is fine!
The monitoring says so!
![Page 14: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/14.jpg)
idn facepalms
![Page 15: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/15.jpg)
Everything is not fine
● One hub has an issue● Spam Assassin is dead● No problem identified● The monitoring is wrong
![Page 16: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/16.jpg)
Service was affected.Messages were delayed.
![Page 17: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/17.jpg)
Service was affected.Messages were delayed.
#fail
![Page 18: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/18.jpg)
So what's the problem?
● Spam Assassin process went away● Exim unable to scan messages● Temporary reject (safe thing to do)
![Page 19: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/19.jpg)
How do we test?
![Page 20: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/20.jpg)
Testing
● Spam Assassin provides spamc● Create a batch SMTP file:
helo testing.example.comMAIL FROM: "Person, A" <[email protected]>RCPT TO: [email protected]: Testing viagraTo: [email protected]: "Person, A" <[email protected]>
Test SMTP session.QUIT
![Page 21: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/21.jpg)
Testing
● spamc -c -B < bsmtp-file● Exit status zero or one
![Page 22: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/22.jpg)
Enter Perl
● List of files to test & expected return● Test files and check return
![Page 23: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/23.jpg)
# Files to test along with expected exit valuemy $files = { "01spamassassinnormalmessage.txt" => 0, "02spamassassinspammymessage.txt" => 1,};
my $fail = 0;
# Scan each of the files in the hashforeach my $file (keys(%$files)) {
# Check the file system("/usr/bin/spamc c B < $file > /dev/null");
# Bitshift $? to get the exit code my $exitval = $CHILD_ERROR >> 8;
# Compare the exit value to that expected if($exitval != $files>{$file}) { $fail = 1; last; }}
![Page 24: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/24.jpg)
# Files to test along with expected exit valuemy $files = { "01spamassassinnormalmessage.txt" => 0, "02spamassassinspammymessage.txt" => 1,};
my $fail = 0;
# Scan each of the files in the hashforeach my $file (keys(%$files)) {
# Check the file system("/usr/bin/spamc c B < $file > /dev/null");
# Bitshift $? to get the exit code my $exitval = $CHILD_ERROR >> 8;
# Compare the exit value to that expected if($exitval != $files>{$file}) { $fail = 1; last; }}
Files totest
Expectedexit
value
![Page 25: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/25.jpg)
Write status to a file
open(my $fh, '>', '/tmp/sastatus') or die('Cannot open file');print($fh $fail);close($fh);
![Page 26: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/26.jpg)
So we know #fail.
Now what?!
![Page 27: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/27.jpg)
SNMP
● Add SNMP!
● snmpd.confextend sastatus /bin/cat /tmp/sastatus
![Page 28: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/28.jpg)
SNMP
● snmpwalk$ snmpwalk v2c c public 127.0.0.1 .1.3.6.1.4.1.8072.1.3.2 NETSNMPEXTENDMIB::nsExtendNumEntries.0 = INTEGER: 1NETSNMPEXTENDMIB::nsExtendCommand."sastatus" = STRING: /bin/catNETSNMPEXTENDMIB::nsExtendArgs."sastatus" = STRING: /tmp/sastatusNETSNMPEXTENDMIB::nsExtendInput."sastatus" = STRING: NETSNMPEXTENDMIB::nsExtendCacheTime."sastatus" = INTEGER: 5NETSNMPEXTENDMIB::nsExtendExecType."sastatus" = INTEGER: exec(1)NETSNMPEXTENDMIB::nsExtendRunType."sastatus" = INTEGER: runonread(1)NETSNMPEXTENDMIB::nsExtendStorage."sastatus" = INTEGER: permanent(4)NETSNMPEXTENDMIB::nsExtendStatus."sastatus" = INTEGER: active(1)NETSNMPEXTENDMIB::nsExtendOutput1Line."sastatus" = STRING: 1NETSNMPEXTENDMIB::nsExtendOutputFull."sastatus" = STRING: 1NETSNMPEXTENDMIB::nsExtendOutNumLines."sastatus" = INTEGER: 1NETSNMPEXTENDMIB::nsExtendResult."sastatus" = INTEGER: 0NETSNMPEXTENDMIB::nsExtendOutLine."sastatus".1 = STRING: 1
![Page 29: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/29.jpg)
SNMP
● snmpwalk$ snmpwalk v2c c public 127.0.0.1 .1.3.6.1.4.1.8072.1.3.2 NETSNMPEXTENDMIB::nsExtendNumEntries.0 = INTEGER: 1NETSNMPEXTENDMIB::nsExtendCommand."sastatus" = STRING: /bin/catNETSNMPEXTENDMIB::nsExtendArgs."sastatus" = STRING: /tmp/sastatusNETSNMPEXTENDMIB::nsExtendInput."sastatus" = STRING: NETSNMPEXTENDMIB::nsExtendCacheTime."sastatus" = INTEGER: 5NETSNMPEXTENDMIB::nsExtendExecType."sastatus" = INTEGER: exec(1)NETSNMPEXTENDMIB::nsExtendRunType."sastatus" = INTEGER: runonread(1)NETSNMPEXTENDMIB::nsExtendStorage."sastatus" = INTEGER: permanent(4)NETSNMPEXTENDMIB::nsExtendStatus."sastatus" = INTEGER: active(1)NETSNMPEXTENDMIB::nsExtendOutput1Line."sastatus" = STRING: 1NETSNMPEXTENDMIB::nsExtendOutputFull."sastatus" = STRING: 1NETSNMPEXTENDMIB::nsExtendOutNumLines."sastatus" = INTEGER: 1NETSNMPEXTENDMIB::nsExtendResult."sastatus" = INTEGER: 0NETSNMPEXTENDMIB::nsExtendOutLine."sastatus".1 = STRING: 1
![Page 30: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/30.jpg)
Now we can monitor!
![Page 31: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/31.jpg)
OpenNMS
● poller-configuration.xml <service name="SAStatus" interval="300000" userdefined="false" status="on"> <parameter key="retry" value="2"/> <parameter key="timeout" value="3000"/> <parameter key="port" value="161"/> <parameter key="oid" value=".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.115.97.45.115.116.97.116.117.115.1"/> <parameter key="operator" value="="/> <parameter key="operand" value="0"/> </service>
<monitor service="SAStatus" classname="org.opennms.netmgt.poller.monitors.SnmpMonitor" />
![Page 32: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/32.jpg)
OpenNMS
● poller-configuration.xml <service name="SAStatus" interval="300000" userdefined="false" status="on"> <parameter key="retry" value="2"/> <parameter key="timeout" value="3000"/> <parameter key="port" value="161"/> <parameter key="oid" value=".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.115.97.45.115.116.97.116.117.115.1"/> <parameter key="operator" value="="/> <parameter key="operand" value="0"/> </service>
<monitor service="SAStatus" classname="org.opennms.netmgt.poller.monitors.SnmpMonitor" />
Commandoutput
![Page 33: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/33.jpg)
OpenNMS
● poller-configuration.xml <service name="SAStatus" interval="300000" userdefined="false" status="on"> <parameter key="retry" value="2"/> <parameter key="timeout" value="3000"/> <parameter key="port" value="161"/> <parameter key="oid" value=".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.115.97.45.115.116.97.116.117.115.1"/> <parameter key="operator" value="="/> <parameter key="operand" value="0"/> </service>
<monitor service="SAStatus" classname="org.opennms.netmgt.poller.monitors.SnmpMonitor" />
Externalcommandnumber
![Page 34: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/34.jpg)
Erk.
#fail.
+++OUT OF CHEESE+++
![Page 35: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/35.jpg)
OpenNMS
● poller-configuration.xml <service name="SAStatus" interval="300000" userdefined="false" status="on"> <parameter key="retry" value="2"/> <parameter key="timeout" value="3000"/> <parameter key="port" value="161"/> <parameter key="oid" value=".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.115.97.45.115.116.97.116.117.115.1"/> <parameter key="operator" value="="/> <parameter key="operand" value="0"/> </service>
<monitor service="SAStatus" classname="org.opennms.netmgt.poller.monitors.SnmpMonitor" />
Length ofidentifier
“sa-status”Thanks to roskens on
#opennms for pointing outthat this was wrong.
Cheers! :)
![Page 36: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/36.jpg)
OpenNMS
● poller-configuration.xml <service name="SAStatus" interval="300000" userdefined="false" status="on"> <parameter key="retry" value="2"/> <parameter key="timeout" value="3000"/> <parameter key="port" value="161"/> <parameter key="oid" value=".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.115.97.45.115.116.97.116.117.115.1"/> <parameter key="operator" value="="/> <parameter key="operand" value="0"/> </service>
<monitor service="SAStatus" classname="org.opennms.netmgt.poller.monitors.SnmpMonitor" />
“sa-status”
![Page 37: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/37.jpg)
OpenNMS
● poller-configuration.xml <service name="SAStatus" interval="300000" userdefined="false" status="on"> <parameter key="retry" value="2"/> <parameter key="timeout" value="3000"/> <parameter key="port" value="161"/> <parameter key="oid" value=".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.115.97.45.115.116.97.116.117.115.1"/> <parameter key="operator" value="="/> <parameter key="operand" value="0"/> </service>
<monitor service="SAStatus" classname="org.opennms.netmgt.poller.monitors.SnmpMonitor" />
Linenumber ofcommand
output
![Page 38: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/38.jpg)
OpenNMS
● poller-configuration.xml <service name="SAStatus" interval="300000" userdefined="false" status="on"> <parameter key="retry" value="2"/> <parameter key="timeout" value="3000"/> <parameter key="port" value="161"/> <parameter key="oid" value=".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.115.97.45.115.116.97.116.117.115.1"/> <parameter key="operator" value="="/> <parameter key="operand" value="0"/> </service>
<monitor service="SAStatus" classname="org.opennms.netmgt.poller.monitors.SnmpMonitor" />
Commandoutput
“sa-status”
Linenumber ofcommand
output
Length ofidentifier
“sa-status”
![Page 39: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/39.jpg)
Provisioning
● Foreign source
● Node
![Page 40: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/40.jpg)
That works!
![Page 41: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/41.jpg)
That works!
But it sucks!
![Page 42: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/42.jpg)
Issues
● Stale file?● Not SNMP tables - no way to instance map● Works for simple data● Can have multiple lines● Assumes ordering with multiple lines
![Page 43: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/43.jpg)
Issues
● Want to add a service● Want to remove a service● Want to re-order my file● …...
![Page 44: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/44.jpg)
Issues
● Want to add a service● Want to remove a service● Want to re-order my file (OCD attack)● …...
![Page 45: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/45.jpg)
Mail queue size
● Want to track destination domains● Which are queueing● Which are local, remote, etc
![Page 46: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/46.jpg)
Our single file approachdoes not scale.
![Page 47: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/47.jpg)
Our single file approachdoes not scale.
Add cloud more files!
![Page 48: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/48.jpg)
Output to two files
● Keys● Values
● The data can change● OpenNMS will map together for us● Add a timestamp
![Page 49: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/49.jpg)
Output to two files
# Open the files to work withmy $file = $path . $counter . '_';my $keys_file = IO::File>new( $file . 'keys', 'w' ) or croak($OS_ERROR);my $stats_file = IO::File>new( $file . 'stats', 'w' ) or croak($OS_ERROR);
my $timestamp = time();
# Output the current timestamp to both files$keys_file>print("$timestamp\n");$stats_file>print("$timestamp\n");
# Output the keys and stats to the relevant files.foreach my $key ( sort( keys( %{$stats} ) ) ) { $keys_file>print("$key\n"); $stats_file>print( $stats>{$key} . "\n" );}
# Close the File::IO objects$keys_file>close();$stats_file>close();
![Page 50: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/50.jpg)
Generate the data
● Exim has exipick● --flatq option is designed for parsing● Options for extra data
![Page 51: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/51.jpg)
Generate the data# Set the exipick binary & CLI optionsmy $exipick_cmd = "/usr/sbin/exipick";my $exipick_opt = "flatq showvars message_size,deliver_freeze";
# Initialise interesting domain counters and the two catchall domains.my %domains = ('exchange.example.com' => 0, 'dept1.example.com' => 0, '*.example.com' => 0, # Catchall for other example.com 'internal' => 0, # Counter for all internal 'external' => 0, # Catchall for everything else);
# Run the exipick command and process the output.open(my $exipick, '|', "$exipick_cmd $exipick_opt");
# Loop through the command outputwhile(<$exipick>) { chomp;
my $line = $_;
# Split the showvars with spaces rather than semicolons $line =~ s/;/ /g;
# Send the exipick line to be processed. process_line($line);}
close($exipick);
![Page 52: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/52.jpg)
Generate the datasub process_line { my $line = shift;
# Sample exipick output line with email address changed to anonymise: # 4d message_size='9265' deliver_freeze='' 1E9hWO0001AH4A <> [email protected]
# Split the output line using a regexp if($line =~ m/.* message_size='(\d*)' deliver_freeze='(.*)' (.*.*.*) <(.*)> (.*)/){ my $msg_size = $1; my $msg_frozen = $2; my $msg_id = $3; my $msg_sender = $4; my $msg_recipient = $5;
# Send the recipient email address to process domain for a breakdown. process_domain($msg_recipient); }}
![Page 53: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/53.jpg)
Generate the datasub process_domain { my $email = shift;
# Get the domain from the email address. my $domain = $email; $domain =~ s/^.*@//;
# Is this an internal domain? if($domain =~ m/example.com$/) { $domains{'internal'}++; }
# If this domain exists, increment the counter for that domain. if(defined($domains{$domain})) { $domains{$domain}++; }
# Increment the catchall counter for *.example.com addresses elsif ($domain =~ m/example.com$/) { $domains{'*.example.com'}++; }
# Increment the external counter for everything else else { $domains{'external'}++; }}
![Page 54: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/54.jpg)
Generate the data
$VAR1 = { 'dept1.example.com' => 34, 'exchange.example.com' => 26, 'external' => 43, 'internal' => 110, '*.example.com' => 50 };
● Generates this data:
● Which writes our two files
/tmp/mailq_keys
/tmp/mailq_stats
![Page 55: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/55.jpg)
SNMP
● snmpd.conf
extend mailqkeys /bin/cat /tmp/mailq_keysextend mailqstats /bin/cat /tmp/mailq_stats
![Page 56: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/56.jpg)
SNMP
● snmpwalk$ snmpwalk v2c c public 127.0.0.1 NETSNMPEXTENDMIB::nsExtendOutLineNETSNMPEXTENDMIB::nsExtendOutLine."mailqkeys".1 = STRING: 1534221421134720NETSNMPEXTENDMIB::nsExtendOutLine."mailqkeys".2 = STRING: *.example.comNETSNMPEXTENDMIB::nsExtendOutLine."mailqkeys".3 = STRING: exchange.example.comNETSNMPEXTENDMIB::nsExtendOutLine."mailqkeys".4 = STRING: dept1.example.comNETSNMPEXTENDMIB::nsExtendOutLine."mailqkeys".5 = STRING: internalNETSNMPEXTENDMIB::nsExtendOutLine."mailqkeys".6 = STRING: externalNETSNMPEXTENDMIB::nsExtendOutLine."mailqstats".1 = STRING: 1534221421134720NETSNMPEXTENDMIB::nsExtendOutLine."mailqstats".2 = STRING: 50NETSNMPEXTENDMIB::nsExtendOutLine."mailqstats".3 = STRING: 26NETSNMPEXTENDMIB::nsExtendOutLine."mailqstats".4 = STRING: 34NETSNMPEXTENDMIB::nsExtendOutLine."mailqstats".5 = STRING: 110NETSNMPEXTENDMIB::nsExtendOutLine."mailqstats".6 = STRING: 43
![Page 57: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/57.jpg)
Now we can monitor!
![Page 58: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/58.jpg)
OpenNMS
<resourceType name="eximMailQueueInst" label="Exim mail queue"> <persistenceSelectorStrategy class="org.opennms.netmgt.collectd.PersistRegexSelectorStrategy"> <parameter key="matchexpression" value="not(#eximMailQueueKey matches '^\d+$')" /> </persistenceSelectorStrategy>
<storageStrategy class="org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy"> <parameter key="siblingcolumnname" value="eximMailQueueKey" /> <parameter key="replaceall" value="s/\s/_/" /> </storageStrategy> </resourceType>
![Page 59: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/59.jpg)
OpenNMS
<group name="eximmailq" ifType="ignore"> <mibObj oid=".1.3.6.1.4.1.8072.1.3.2.4.1.2.10.109.97.105.108.113.45.107.101.121.115" instance="eximMailQueueInst" alias="eximMailQueueKey" type="string" /> <mibObj oid=".1.3.6.1.4.1.8072.1.3.2.4.1.2.11.109.97.105.108.113.45.115.116.97.116.115" instance="eximMailQueueInst" alias="eximMailQueueStat" type="gauge" /> </group>
<systemDef name="Exim monitoring"> <sysoidMask>.1.3.6.1.4.1.8072.3.2.10</sysoidMask> <collect> <includeGroup>eximmailq</includeGroup> </collect> </systemDef>
![Page 60: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/60.jpg)
Graphs!
# Reports list for Eximreports=exim.eximMailQueueKey, exim.eximMailQueueStat
report.exim.eximMailQueueStat.name=Messagesreport.exim.eximMailQueueStat.columns=eximMailQueueStatreport.exim.eximMailQueueStat.propertiesValues=eximMailQueueKeyreport.exim.eximMailQueueStat.type=eximMailQueueInstreport.exim.eximMailQueueStat.command=title="{eximMailQueueKey}" \ DEF:messages={rrd1}:eximMailQueueStat:AVERAGE \ LINE2:messages#0000ff:"Messages" \ GPRINT:messages:AVERAGE:" Avg \\: %2.0lf %s" \ GPRINT:messages:MIN:" Min \\: %2.0lf %s" \ GPRINT:messages:MAX:" Max \\: %2.0lf %s\\n"
![Page 61: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/61.jpg)
Graphs!
![Page 62: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/62.jpg)
OpenNMS
● Now we get thresholding● And all the fun of the NMS!
![Page 63: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/63.jpg)
Further expansion
● Antivirus● Total number of messages● Log file parsing● Message transit times● RBL monitoring
![Page 64: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/64.jpg)
Questions?
![Page 65: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/65.jpg)
Thanks!
![Page 66: Exim, Perl and SNMP! Oh my! Ian Norton Shadowcat - agaton](https://reader031.vdocuments.net/reader031/viewer/2022021209/62063a008c2f7b173005a4e7/html5/thumbnails/66.jpg)
Slides available at:http://agaton.scsys.co.uk/~iann/talks/
idn on irc.perl.org and irc.freenode.net