Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

Script to reboot SRX at 95% CPU and above

‎02-22-2017 07:14 AM

Can somebody guide me how to write a script to issue a "request system reboot" at specific time, lets say 2 AM when CPU is constantly spiking and staying at 95% and above for more than 24 hours.

 

 

I tried creating event-options and policy based on that but there is no event for high cpu utilization. 

 

Thank you for your time.

JNCIA JNCIS-Sec JNCIP-Sec
JNCIS-DevOps
1 ACCEPTED SOLUTION

Accepted Solutions
Junos Automation (Scripting)
Solution
Accepted by topic author Ankitvora
‎02-11-2019 11:32 AM

Re: Script to reboot SRX at 95% CPU and above

‎02-11-2019 11:31 AM

Attaching the script I was talking about,

 

rmon {
alarm 1 {
interval 10;
variable jnxOperatingCPU.9.1.0.0;
sample-type absolute-value;
rising-threshold 70;
rising-event-index 1;
}
event 1 {
type log;
}
}

 

policy test {
events snmpd_rmon_eventlog;
then {
execute-commands {
commands {
"set cli timestamp";
"set task accounting on";
"show task accounting detail";
"show krt queue";
"show krt state";
"show chassis routing-engine |no-more";
"show system uptime |no-more";
"show system connections | no-more";
"show system processes extensive no-forwarding | no-more";
"show system statistics | no-more";
"show system virtual-memory no-forwarding | no-more";
"show task memory detail | no-more";
"show task memory summary | no-more";
"show task io";
"show task statistics";
"show task jobs";
"set task accounting off";
}
output-filename CPU-GET-HIGH.txt;
destination log-for-CPU-GET-HIGH;
output-format text;
}
}
}

JNCIA JNCIS-Sec JNCIP-Sec
JNCIS-DevOps
4 REPLIES 4
Junos Automation (Scripting)

Re: Script to reboot SRX at 95% CPU and above

‎02-24-2017 10:37 AM

Hello Ankitvora,


You can mix RMON & event script: 

create RMON event trigger ---- > create event srcipt to match on the generated rmon alarm. 

 

I found an old discussion regarding this, please find the link below


http://forums.juniper.net/t5/Junos-Automation-Scripting/event-script-for-CPU-utilization/td-p/135063

 

Thank you, 

Mahdy 

Junos Automation (Scripting)

Re: Script to reboot SRX at 95% CPU and above

‎02-27-2017 07:08 AM

Thank you this is a good discussion i think i can connect the dots now and move forward. I ll post my script once I am done with it.

JNCIA JNCIS-Sec JNCIP-Sec
JNCIS-DevOps
Junos Automation (Scripting)
Solution
Accepted by topic author Ankitvora
‎02-11-2019 11:32 AM

Re: Script to reboot SRX at 95% CPU and above

‎02-11-2019 11:31 AM

Attaching the script I was talking about,

 

rmon {
alarm 1 {
interval 10;
variable jnxOperatingCPU.9.1.0.0;
sample-type absolute-value;
rising-threshold 70;
rising-event-index 1;
}
event 1 {
type log;
}
}

 

policy test {
events snmpd_rmon_eventlog;
then {
execute-commands {
commands {
"set cli timestamp";
"set task accounting on";
"show task accounting detail";
"show krt queue";
"show krt state";
"show chassis routing-engine |no-more";
"show system uptime |no-more";
"show system connections | no-more";
"show system processes extensive no-forwarding | no-more";
"show system statistics | no-more";
"show system virtual-memory no-forwarding | no-more";
"show task memory detail | no-more";
"show task memory summary | no-more";
"show task io";
"show task statistics";
"show task jobs";
"set task accounting off";
}
output-filename CPU-GET-HIGH.txt;
destination log-for-CPU-GET-HIGH;
output-format text;
}
}
}

JNCIA JNCIS-Sec JNCIP-Sec
JNCIS-DevOps
Junos Automation (Scripting)

Re: Script to reboot SRX at 95% CPU and above

‎02-11-2019 02:46 PM

One year development cycle?