Intermediary EEM scripting: more fun with Power-over-Ethernet

In my last post I described how you can power off PoE on a range of switchports at certain times. But what if you’re lazy like me and don’t want to spend time figuring out which ports are utilizing Power-over-Ethernet? Can’t mr. switch do this himself? Well yes he can! Here you go:

event manager applet SelectivePowerOff
 action 0.0 cli command "enable"
 action 0.1 cli command "show power inline"
 action 0.2 foreach line "$_cli_result" "\n"
 action 1.1  regexp "^([^[:space:]]*)[[:space:]]*[^[:space:]]*[[:space:]]*on.*$" "$line" temp interface
 action 1.2  if $_regexp_result eq 1
 action 1.3   cli command "conf t"
 action 1.4   cli command "interface $interface"
 action 1.5   cli command "power inline never"
 action 1.6   syslog msg "Turned off PoE on $interface"
 action 1.7  end
 action 2.1 end

Basically what we’re doing here is using the “show power inline” command and processing it line by line. If we find an interface where the PoE operational status (column “Oper”) is on, we run the command “power inline never” on that interface. We also log a message to syslog telling we’ve turned off the power on that interface.

event manager applet SelectivePowerOn
 action 0.0 cli command "enable"
 action 0.1 cli command "show power inline"
 action 0.2 foreach line "$_cli_result" "\n"
 action 1.1  regexp "^([^[:space:]]*)[[:space:]]*off.*$" "$line" temp interface
 action 1.2  if $_regexp_result eq 1
 action 1.3   cli command "conf t"
 action 1.4   cli command "interface $interface"
 action 1.5   cli command "no power inline never"
 action 1.6   syslog msg "Turned on PoE on $interface"
 action 1.7  end
 action 2.1 end
 exit

Here we go through the same “show power inline” and check if the PoE administrative status (column “Admin”) is off. If it is, we run the command “no power inline never” on that interface. We also log a message telling we’ve turned on the power.

If you combine this with the event timer, you’ll have a fully automated solution.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s