What this is? Pretty simple…Juniper started off automating stuff via SLAX, something that did not get too much traction and then Python took the lead in front of it. It is an XML/Xpath based language and for simple things you can find it pretty useful and not so complicated to learn. What the script below does is effectively enabling a MIC upon its insertion into an MX5. Previously someone from operations would have to go manually on the device and enable it.

Table of Contents

The code

% cat /var/db/scripts/event/online_mic_on_insert.slax

*/
version 1.1;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
ns date = "http://exslt.org/dates-and-times";
ns bit extension = "http://xml.libslax.org/bit";
ns str = "http://exslt.org/strings";

import "../import/junos.xsl";

param $message;
param $timeS=30;

var $con = jcs:open();

var $arguments = {
  <argument> {
    <name> "message";
    <description> "Syslog message to be parsed";
  }
}

match / {
  var $match = jcs:regex("cmtfpc_pic_send_status fpc=1 pic=([0-9]) type",$message);
  var $pic = $match[2];
  if ($pic == 0) {
        expr jcs:sleep($timeS);
        call online-mic($mic=0,$fpc=1);
  }
  else if ($pic == 2) {
        expr jcs:sleep($timeS);
        call online-mic($mic=1,$fpc=1);
  }
  expr jcs:syslog("user.warn", "MICON: Online MIC script called by insertion of card for MIC = " _ $mic _ " in slot " _ $fpc );
  expr jcs:close($con);
}

template online-mic($mic,$fpc) {
        var $rpc-online-mic = <command> "request chassis mic mic-slot " _ $mic _ " fpc-slot 1 online";
        expr jcs:syslog("user.warn", "MICON: Onlining FPC 1 MIC Slot " _ $mic );
        var $results = jcs:execute($con,$rpc-online-mic);
        expr jcs:syslog("user.warn", "MICON: Online Script results " _ $results);
}

Enable it in the config of Junos:

```bash Juniper@device> ...configuration | display set | match event set event-options policy online_mic_on_insert events PIC set event-options policy online_mic_on_insert attributes-match PIC.message matches ".* cmtfpc_pic_send_status fpc=[0-9] pic=[0-9] type.*" set event-options policy online_mic_on_insert then event-script online_mic_on_insert.slax arguments message "{$$.message}" set event-options event-script file online_mic_on_insert.slax