Chapter 19. Email

Email on a switch? Hell yes! Arista switches allow emails to be sent from the EOS command line, from bash, from scripts, and from all sorts of interesting places. Once you see this in action, you’ll wonder how you ever lived without it. Ever have to copy the output of a show tech from flash, to a TFTP server, and then to your laptop? You’ll never need to go through that nonsense again with email configured on your Arista switch. Ever copy and paste from the screen, only to discover that your scrollback buffer wasn’t big enough? With email on an Arista switch, just email the output directly to your (or anyone’s) inbox. But enough hype, let’s dig in and see how it’s done.

Arista switches contain an email configuration mode that is accessed with the email command:

Arista#conf t
Arista(config)#email

Once there, hit the question mark and see what’s available:

Arista(config-email)#?
  auth       Email account authentication
  comment    Up to 240 characters, comment for this mode
  default    Set a command to its defaults
  exit       Exit from Email configuration mode
  from-user  Send email from this user
  help       Description of the interactive help system
  no         Negate a command or set its defaults
  server     Email relay
  show       Show running system information
  tls        Require TLS
  !          Append to comment

In its simplest form, mail on an Arista switch requires configuration for a from address and an email server to send through. This is done with the from-user and server commands. Here, I’ll configure the from-user to be , and the server to be 192.168.1.200. If DNS is configured, I could also use a fully qualified domain name such as mail.gad.net:

Arista(config-email)#from-user [email protected]
Arista(config-email)#server 192.168.1.200

While within the email configuration mode, the command show active will display what’s currently configured for email:

Arista(config-email)#show active
email
   from-user [email protected]
   server 192.168.1.200

For more advanced scenarios, email in EOS supports username and password authentication using the cleverly named username and password commands:

Arista(config-email)#auth username gad
Arista(config-email)#auth password ILikePie

If a password is entered in plain text, as I’ve done here, the switch will convert it into an encrypted string. Show active will display this encrypted string, as will the configuration:

Arista(config-email)#sho active
email
   from-user [email protected]
   server 192.168.1.200
   auth username gad
   auth password 7 MHTq67ztWA9dQOfAwOWOqQ==

Warning

Passwords encrypted within configurations are not very secure. Remember that given this configuration, the username and password will be sent over the network in clear text as well.

If your mail server supports Transport Layer Security (TLS), you can enable that with the TLS command:

Arista(config-email)#tls

My lab is not set up for TLS, so it won’t show up in later command outputs. TLS will solve the problem of passwords being sent in clear text, so it’s a recommended solution to use wherever possible.

With my email set up, I’ll now flex my new power by sending the output of a command to my inbox. This can be done with any show command by using the pipe (vertical bar) character followed by the word email. Note that this option does not show up if you search for it:

Arista#sho run | ?
  LINE      Filter command pipeline
  append    Append redirected output to URL
  begin     Begin with the line that matches
  exclude   Exclude lines that match
  include   Include lines that match
  no-more   Disable pagination for this command
  nz        Include only non-zero counters
  redirect  Redirect output to URL
  tee       Copy output to URL

Rest assured, though, that it works. By now it shouldn’t surprise you that email is actually a command in bash that’s referenced from EOS. To see the possible options, drop to bash and issue the email –-help command:

Arista#bash

Arista Networks EOS shell

[admin@Arista ~]$ email --help
Usage: email -- send email through the configured SMTP server

Options:
  -h, --help                       show this help message and exit
  -a, --attachment                 send content as an attachment
  -d, --debug                      debug interaction with SMTP server
  -r REF, --ref=REF                specify case ref
  -s SUBJECT, --subject=SUBJECT    specify subject
  --sysname=SYSNAME                specify Sysdb sysname

Let’s get back to EOS and try some of those. First, I’ll pipe the output of the show run command to my email with a subject of Show Run. I’ll specify a subject for the email with the –s flag, and then list the email address of the intended recipient:

Arista(config-email)#sho run | email -s "Show Run" [email protected]
Arista(config-email)#

No output is displayed since it’s all been redirected to the email program. A quick jump over to my email client, and there’s the email!

Date: Tue, 15 May 2012 01:44:07
From: [email protected]
To: [email protected]
Subject: Show Run

! device: Arista (DCS-7124S, EOS-4.9.3)
!
! boot system flash:/EOS-4.9.3.swi
!
email
   from-user [email protected]
   server 192.168.1.200
!
queue-monitor length
!
hostname Arista
ip name-server 192.168.1.200
ip name-server 4.2.2.2
[---output truncated---]

This time, I’ll send the output of the command show interface e24 to my email, but without specifying a subject. Without a subject specified, a generic subject is inserted on my behalf:

Arista(config-email)#sho int e24 | email [email protected]

Here is the resulting email, with the subject line in bold:

Date: Tue, 15 May 2012 01:48:18
From: [email protected]
To: [email protected]
Subject: Support email sent from the switch

Ethernet24 is down, line protocol is down (notconnect)
  Hardware is Ethernet, address is 001c.7308.80ae
  No Internet protocol address assigned
  MTU 1500 bytes, BW 1000000 Kbit
  Full-duplex, 1Gb/s, auto negotiation: fail
  Down 9 hours, 1 minutes, 39 seconds
  Last clearing of "show interface" counters never
  5 minutes input rate 0 bps (0.0% with framing), 0 packets/sec
  5 minutes output rate 0 bps (0.0% with framing), 0 packets/sec
     0 packets input, 0 bytes
     Received 0 broadcasts, 0 multicast
     0 runts, 0 giants
     0 input errors, 0 CRC, 0 alignment, 0 symbol
     0 PAUSE input
     0 packets output, 0 bytes
     Sent 0 broadcasts, 0 multicast
     0 output errors, 0 collisions
     0 late collision, 0 deferred
     0 PAUSE output

Let’s try and do our show interface command, but this time send it as an attachment by using the –a flag. Let’s specify a subject this time too:

Arista#sho int e24 | email -s "Sho int e24" [email protected] -a

And here’s what I see in Pine (yes, I still use Pine [Alpine, actually] as my email client):

Date: Tue, 15 May 2012 01:53:47
From: [email protected]
To: [email protected]
Subject: Sho int e24
Parts/Attachments:
   1 Shown     2 lines  Text
   2   OK     20 lines  Text
----------------------------------------
see attachment


    [ Part 2, Text/PLAIN 20 lines. ]
    [ Not Shown. Use the "V" command to view or save this part. ]

Flummoxed by email failures after you’ve configured your switch for this feature? You can specify the –d option with email, after which you will be rewarded with pages of debug information reflecting every detailed interaction performed by the email process. Let’s take a look:

Arista#sho int e24 | email -d [email protected]
connect: ('192.168.1.200', 25)
connect: (25, '192.168.1.200')
reply: '220 mail.example.com ESMTP Postfix (Ubuntu)
'
reply: retcode (220); Msg: mail.example.com ESMTP Postfix (Ubuntu)
connect: mail.example.com ESMTP Postfix (Ubuntu)
send: 'ehlo [127.0.0.1]
'
reply: '250-mail.example.com
'
reply: '250-PIPELINING
'
reply: '250-SIZE 30000000
'
reply: '250-VRFY
'
reply: '250-ETRN
'
reply: '250-STARTTLS
'
reply: '250-ENHANCEDSTATUSCODES
'
reply: '250-8BITMIME
'
reply: '250 DSN
'
reply: retcode (250); Msg: mail.example.com
PIPELINING
SIZE 30000000
VRFY
ETRN
STARTTLS
ENHANCEDSTATUSCODES
8BITMIME
DSN
send: 'mail FROM:<[email protected]> size=1038
'
reply: '250 2.1.0 Ok
'
reply: retcode (250); Msg: 2.1.0 Ok
send: 'rcpt TO:<[email protected]>
'
reply: '250 2.1.5 Ok
'
reply: retcode (250); Msg: 2.1.5 Ok
send: 'data
'
reply: '354 End data with <CR><LF>.<CR><LF>
'
reply: retcode (354); Msg: End data with <CR><LF>.<CR><LF>
data: (354, 'End data with <CR><LF>.<CR><LF>')
send: 'Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0

    
Content-Transfer-Encoding: 7bit
To: [email protected]
Subject:
 Support email sent from the switch
Message-ID: 
     <20120515231040.24975.45112.email@Arista>
Date: Tue, 15 May 2012
19:10:40 −0400
From: [email protected]

Ethernet24 is down,
line protocol is down (notconnect)
  Hardware is Ethernet, address
 is 001c.7308.80ae
  No Internet protocol address assigned
  MTU
 1500 bytes, BW 1000000 Kbit
  Full-duplex, 1Gb/s, auto
negotiation: fail
  Down 1 days, 2 hours, 24 minutes, 1
seconds
  Last clearing of "show interface" counters never

 5 minutes input rate 0 bps (0.0% with framing), 0 packets/sec

 5 minutes output rate 0 bps (0.0% with framing), 0 packets/sec

     0 packets input, 0 bytes
     Received 0 broadcasts, 0
multicast
     0 runts, 0 giants
     0 input errors, 0 CRC,
 0 alignment, 0 symbol
     0 PAUSE input
     0 packets
output, 0 bytes
     Sent 0 broadcasts, 0 multicast
     0
output errors, 0 collisions
     0 late collision, 0 deferred

     0 PAUSE output
.
'
reply: '250 2.0.0 Ok: queued as D9D1D8EC5B4
'
reply: retcode (250); Msg: 2.0.0 Ok: queued as D9D1D8EC5B4
data: (250, '2.0.0 Ok: queued as D9D1D8EC5B4')
send: 'quit
'
reply: '221 2.0.0 Bye
'
reply: retcode (221); Msg: 2.0.0 Bye

In this case, everything went through fine. This output would be invaluable during a failure. Here, I’ve misconfigured the server’s IP address in my email configuration in order to generate a failed connection:

Arista#sho int e24 | email -d -s "Show Int e24" [email protected]
connect: ('192.168.1.203', 25)
connect: (25, '192.168.1.203')
% Failed to send email: [Errno 113] No route to host

Here, I’ve mistakenly sent an email to an address that doesn’t exist on my server:

Arista#sho int e24 | email -d -s "Show Int e24" [email protected]
connect: ('192.168.1.200', 25)
connect: (25, '192.168.1.200')
reply: '220 mail.example.com ESMTP Postfix (Ubuntu)
'
reply: retcode (220); Msg: mail.example.com ESMTP Postfix (Ubuntu)
connect: mail.example.com ESMTP Postfix (Ubuntu)
send: 'ehlo [127.0.0.1]
'
reply: '250-mail.example.com
'
reply: '250-PIPELINING
'
reply: '250-SIZE 30000000
'
reply: '250-VRFY
'
reply: '250-ETRN
'
reply: '250-STARTTLS
'
reply: '250-ENHANCEDSTATUSCODES
'
reply: '250-8BITMIME
'
reply: '250 DSN
'
reply: retcode (250); Msg: mail.example.com
PIPELINING
SIZE 30000000
VRFY
ETRN
STARTTLS
ENHANCEDSTATUSCODES
8BITMIME
DSN
send: 'mail FROM:<[email protected]> size=1018
'
reply: '250 2.1.0 Ok
'
reply: retcode (250); Msg: 2.1.0 Ok
send: 'rcpt TO:<[email protected]>
'
reply: '550 5.1.1 <[email protected]>: Recipient address rejected: User
unknown in local recipient table
'
reply: retcode (550); Msg: 5.1.1 <[email protected]>: Recipient address
rejected: User unknown in local recipient table
send: 'rset
'
reply: '250 2.0.0 Ok
'
reply: retcode (250); Msg: 2.0.0 Ok
send: 'quit
'
reply: '221 2.0.0 Bye
'
reply: retcode (221); Msg: 2.0.0 Bye
% None of the addresses were valid: [email protected]: 550 5.1.1
<[email protected]>: Recipient address rejected: User unknown in local
recipient table

Since email is actually a bash command, you can use it for redirecting output in bash, too. Here, I’ve redirected the output of ls -al to my email address:

[admin@Arista ~]$ ls -al | email -s "ls -al" [email protected]

And here’s the output from Pine:

Date: Tue, 15 May 2012 19:35:01
From: [email protected]
To: [email protected]
Subject: ls -al

total 16
drwxr-x--- 3 admin eosadmin 160 May 15 01:34 .
drwxr-xr-x 3 root  root      60 May 15 01:23 ..
-rw------- 1 admin eosadmin 542 May 15 19:10 .bash_history
-rw-r--r-- 1 admin eosadmin  17 May 15 01:23 .bash_logout
-rw-r--r-- 1 admin eosadmin 176 May 15 01:23 .bash_profile
-rw-r--r-- 1 admin eosadmin 124 May 15 01:23 .bashrc
-rw-r--r-- 1 admin eosadmin   0 May 15 01:23 .dircolors
drwxr-xr-x 8 admin eosadmin 160 May 15 01:29 .esmtp_queue

If you’re like me, you’ll find yourself using this feature a lot more than you ever thought you would. But then, I’ve been told there aren’t a lot of people quite like me.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.114.221