Scripting How-To: poesched helps save energy and costs

By Erdem posted 08-14-2015 14:55

  
Overview

 

Disable PoE ports during non-business hours to save energy and cut costs. This applies to SLAX version 1.0 and higher.

Description

Save power and reduce costs by automatically disabling some of the network power consumption during non-business hours. Automatically turn power on and off to PoE ports on a specific schedule for defined locations.

Once activated, this script will be triggered once every hour, comparing the on and off configurations with the actual times of the configured locations. The PoE ports will be disabled and enabled according to the configured schedules.

Set Up

  1. Copy the file poesched.slax to the /var/db/scripts/event directory on the router.
  2. Use a text editor to create the configuration below. On the lines marked EDIT HERE, customize each of the off and on timeframes to match the location needs. The hours are recorded in 24-hour notation. Also change all interface names to match valid names.
    01 poe {
    02     apply-macro scheduler-admin {
    03         off 8; /* EDIT HERE */
    04         on 4; /* EDIT HERE */
    05     }
    06      apply-macro scheduler-finance {
    07         off 1; /* EDIT HERE */
    08         on 9; /* EDIT HERE */
    09     }
    10     interface ge-0/0/0 { /* EDIT HERE */
    11         apply-macro scheduler {
    12             group admin;
    13         }
    14 }
    15     interface ge-0/0/1 { /* EDIT HERE */
    16         apply-macro scheduler {
    17             group admin;
    18         }
    19     }
    20 }
  3. Save this configuration and copy it to the clipboard.
  4. Enable the script by adding the file statement and script filename to the [edit event-options event-script] hierarchy level in the configuration. Only superusers can enable scripts in the configuration.
    1 [edit event-options event-script]
    2 user@host# set file poesched.slax
  5. On the device, enter configuration mode:
    1 user@host% cli
    2 user@host> configure
    3 Entering configuration mode
    4 [edit]
    5 user@host#
  6. Use the load merge terminal command to load the configuration information and merge it with the current configuration:
    1 [edit]
    2 user@host# load merge terminal
    3 [Type ^D at a new line to end input]
    4 > Paste the contents of the clipboard here <
  7. At the prompt, paste the contents of the clipboard.
  8. Press Enter.
  9. Press Ctrl+D.
  10. Commit the configuration.
    1 [edit]
    2 user@host# commit and-quit
 

How to Run

 

This event script will be launched on the occurrence of the event poe-scheduler-start, which will be triggered once in every hour. For simplicity, this script will be executed within an hour of the specified time. It does not guarantee changes on the exact time.

Source Code

GitHub Links

Example Configuration

 
 
01
Step 1: Configure
02
 
03
a.      Copy the file 'poesched.slax' to '/var/db/scripts/event/'.
04
 
05
b.  Using a text editor, create following configuration and copy it to
06
the clipboard
07
    poe {
08
        apply-macro scheduler-admin {
09
            off 8; /* EDIT HERE */
10
            on 4; /* EDIT HERE */
11
        }
12
        apply-macro scheduler-finance {
13
            off 1; /* EDIT HERE */
14
            on 9; /* EDIT HERE */
15
        }
16
        interface ge-0/0/0 { /* EDIT HERE */
17
            apply-macro scheduler {
18
                group admin;
19
            }
20
        }
21
        interface ge-0/0/1 { /* EDIT HERE */
22
            apply-macro scheduler {
23
                group admin;
24
            }
25
        }
26
    }
27
 
28
NOTE: In the above mentioned configuration the time against 'on/off'
29
keywords need to be customized according to the need (It is in 24-hour
30
notation). The interface names should also be changed to valid interface
31
names (Look for the EDIT HERE keyword).
32
 
33
c.      Add the script to the [edit event-options event-script] hierarchy
34
level using the file statement. Only users in the superuser class can
35
configure the event scripts.
36
 
37
                [edit event-options event-script]
38
                user@host# set file poesched.slax
39
 
40
d.  On the device, enter configuration mode
41
                user@host% cli
42
                user@host> configure
43
                Entering configuration mode
44
 
45
                [edit]
46
                user@host#
47
e.  Load the configuration file:
48
        [edit]
49
                user@host# load merge terminal
50
f.  At the prompt, past the contents of the clipboard
51
        [edit]
52
        user@host# load merge terminal
53
        [Type ^D at a new line to end input]
54
        > Paste the contents of the clipboard here <
55
g.  Hit Enter
56
h.  Enter Ctrl+d
57
i.  Commit the configuration
58
                [edit]
59
            user@host# commit and-quit
60
 
61
Step 2: Run
62
This event script will get executed on the occurrence of the event
63
'poe-scheduler-start', which will be triggered once in every hour.
64
 
65
Note: An event is triggered every hour but not necessarily at the top
66
of the hour, it could trigger 15 minutes into every hour, 42 minutes into
67
every hour, etc.  Also, if the poe interface has a macro configured that
68
specifies that poe should be turned on/off during that hour then the
69
config will change.

SLAX Script Contents