Created
July 9, 2020 17:30
-
-
Save tonusoo/084ac04cab30151ce7d2911a13320838 to your computer and use it in GitHub Desktop.
enable the event script with "set event-options event-script file check_jdhcpd.slax"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
import "../import/junos.xsl"; | |
var $event-definition = { | |
<event-options> { | |
<generate-event> { | |
<name> "check_jdhcpd_event"; | |
<time-interval> "60"; | |
<no-drift>; | |
} | |
<policy> { | |
<name> "check_jdhcpd"; | |
<events> "check_jdhcpd_event"; | |
<then> { | |
<event-script> { | |
<name> "check_jdhcpd.slax"; | |
} | |
} | |
} | |
} | |
} | |
template exit($slvl, $msg) { | |
expr jcs:syslog("external." _ $slvl, $script _ ": ", $msg); | |
terminate; | |
} | |
match / { | |
<event-script-results> { | |
var $con = jcs:open(); | |
if (not($con)) { | |
call exit($slvl = "error", $msg = "unable to connect to local mgd"); | |
} | |
var $grep_jdhcpd_rpc := { | |
<request-shell-execute> { | |
<command> "ps ax | grep '[j]dhcpd'"; | |
} | |
} | |
var $grep_jdhcpd_result = jcs:execute($con, $grep_jdhcpd_rpc); | |
if ( ! $grep_jdhcpd_result ) { | |
var $restart_jdhcpd_rpc := { | |
<command> "restart dhcp-service"; | |
} | |
var $restart_jdhcpd_result = jcs:execute($con, $restart_jdhcpd_rpc); | |
call exit($slvl = "warning", $msg = "jdhcpd was not running; restarted"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment