Automation
Automation

Scripting How-To: Automatically save and offload support information

by Cordelia on ‎08-10-2015 10:51 PM - edited on ‎09-15-2017 04:08 PM by Administrator Administrator (1,661 Views)

Automatically Save and Offload Support Information 

 

For SLAX version 1.0 and higher, you can automate the collection of system information when specific problem events occur, saving it for later troubleshooting and support. You save time and money researching and troubleshooting problem events, because the exact system status at the time of the event is automatically captured and saved.

 

This policy (baseline-info) is executed on the occurrence of a SYSTEM event as part of a JUNOS daemon or utility crash. When a SYSTEM event occurs that matches a configured attribute, a "request support info" command saves a current view of the system. It collects related information, including error messages, log files, and core dump files, and saves them to a management server for later review and analysis.

 

Set Up

Personalize the conf file with your specific file transfer information:
 
  1. Open the file baseline-info.conf with a text editor (see contents below).
  2.  Look for the line EDIT HERE.
  3.  Replace the generic text in the URL line
    ftp://username:password@remote-machine

    with your specific username, password, and name of your remote-machine where you will be sending the captured event information:

01	event-options {
02	    policy baseline-info {
03	        events SYSTEM;
04	        attributes-match {
05	            SYSTEM.message matches ".*terminated by signal number.*";
06	        }
07	        then {
08	            execute-commands {
09	                 commands {
10	                    "request support information | save
11	                        /var/tmp/baseline-info/request-support-information.txt";
12	                    "file copy /var/log/messages /var/tmp/baseline-info";
13	                    "file copy /var/log/messages.0.gz /var/tmp/baseline-info";
14	                    "file copy /var/log/command /var/tmp/baseline-info";
15	                    "file copy /var/crash/*core* /var/tmp/baseline-info";
16	                    "file copy /var/tmp/*core* /var/tmp/baseline-info";
17	                    "file copy /var/crash/kernel /var/tmp/baseline-info";
18	                    "file archive source /var/tmp/baseline-info compress destination
19	                        /var/tmp/baseline-info.tgz";
20	                    "file copy /var/tmp/baseline-info.tgz
21	                        ftp://username:password@remote-machine//var/tmp/baseline-info.tgz"; /*EDIT HERE */
22	            }
23	            output-format text;
24	            }
25	         }
26	    }
Save your customized baseline-info.conf file and copy its contents to the clipboard.
 
When a specified event occurs, the output is stored in the /var/tmp/baseline-info directory on the router and then copied to a directory of the same name on the remote management server. You will need to create this directory on both devices prior to receiving the output.
 
Create the directory on the router:
 
1	user@host% start shell
2	%mkdir /var/tmp/baseline-info
3	%exit

 

Create the directory on management server:

 

1	%mkdir /var/tmp/baseline-info

 

Log in to your device, start a local shell and run this command to create an empty file /var/tmp/baseline-info for storing the event information: 

 

1	mkdir /var/tmp/baseline-info

 

On the routing platform, enter configuration mode: 

 

1	user@host% cli
2	user@host> configure
3	Entering configuration mode
4	[edit]
5	user@host#

 

Use 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 <
At the prompt, paste the contents of the clipboard (your customized baseline-info.conf) and press Enter. Then, press Ctrl+D to end input.
 
Commit the configuration: 
 
1	[edit]
2	user@host# commit and-quit

 

How to Run

Once your configuration is loaded and committed, the baseline-info configuration is up and running. As soon as a SYSTEM event is triggered which matches the event policy in baseline-info, the baseline information of the device will be gathered, archived, and uploaded to the destination specified in the URL. 
 

 

Example Configuration

1	event-options {
2	    event-script {
3	    file baseline-info.slax;
4	    }
5	}

SLAX Script Contents

001	/*
002	 * Event-script with the following inbuild event-policy configuration in it.
003	 *
004	 * Typically, event-policies are configured under [edit event-options] hierarchy.
005	 * This script illustrates an alternative approach (in JUNOS 9.0) where event-policies
006	 * can be configured inside an event-script. Inside this event-script, event-policies
007	 * configuration has to be specified within a global variable "event-definition"
008	 * in xml format. The xml format for event-policy configuration inside event-scripts
009	 * is the same as JUNOS event-policy configuration in xml format, i.e.
010	 *  user@host> show configuration event-options | display xml   
011	 *
012	 *
013	 * Note: This script assumes that /var/tmp/baseline-info is present in the router,
014	 *       as script currently does not have the capabiility to mkdir.
015	 *
016	 * Usage: Copy this event-script inside /var/db/scripts/event directory
017	 *        and configure it in [edit event-options event-script file baseline-info.slax]
018	 *
019	 *        You may include additional events for triggering this script. To view a list of
020	 *        the events that can be referenced, issue the help syslog ? command
021	 *          user@host> help syslog ?
022	 *        
023	 *        After modifying the event-script, execute
024	 *          user@host> request system scripts event-scripts reload
025	 *        for the changes to get effective
026	 *
027	 *
028	 * event-options {
029	 *   policy baseline-info {
030	 *       events [ ui_restart_event ui_dbase_login_event ];
031	 *       then {
032	 *           execute-commands {
033	 *               commands {
034	 *                   "request support information | save /var/tmp/baseline-info/request-support-information.txt";
035	 *                   "file copy /var/log/messages /var/tmp/baseline-info";
036	 *                   "file copy /var/log/messages.0.gz /var/tmp/baseline-info";
037	 *                   "file copy /var/log/command /var/tmp/baseline-info";
038	 *                   "file copy /var/crash/*core* /var/tmp/baseline-info";
039	 *                   "file copy /var/tmp/*core* /var/tmp/baseline-info";
040	 *                   "file copy /var/crash/kernel /var/tmp/baseline-info";
041	 *                   "file archive source /var/tmp/baseline-info compress destination /var/tmp/baseline-info.tgz";
042	 *                   "file copy /var/tmp/baseline-info.tgz ftp://username:password@remote-machine//var/tmp/baseline-info.tgz";
043	 *               }
044	 *               output-format text;
045	 *           }
046	 *       }
047	 *   }
048	 * }
049	 *
050	 */
051	 
052	version 1.0;
053	 
054	ns junos = "http://xml.juniper.net/junos/*/junos";
055	ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
056	ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
057	ns ext = "http://xmlsoft.org/XSLT/namespace";
058	 
059	var $event-definition = {
060	    <event-options> {
061	        <policy> {
062	        <name> "baseline-info";
063	        <events> "ui_restart_event"; /* add any events here for triggering this script */
064	        <events> "ui_dbase_login_event";
065	        <then> {
066	            <execute-commands> {
067	            <commands> {
068	                <name> "request support information | save /var/tmp/baseline-info/request-support-information.txt";
069	            }
070	            <commands> {
071	                <name> "file copy /var/log/messages /var/tmp/baseline-info";
072	            }
073	            <commands> {
074	                <name> "file copy /var/log/messages.0.gz /var/tmp/baseline-info";
075	            }
076	            <commands> {
077	                <name> "file copy /var/log/command /var/tmp/baseline-info";
078	            }
079	            <commands> {
080	                <name> "file copy /var/crash/*core* /var/tmp/baseline-info";
081	            }
082	            <commands> {
083	                <name> "file copy /var/tmp/*core* /var/tmp/baseline-info";
084	            }
085	            <commands> {
086	                <name> "file copy /var/crash/kernel /var/tmp/baseline-info";
087	            }
088	            <commands> {
089	                <name> "file archive source /var/tmp/baseline-info compress destination /var/tmp/baseline-info.tgz";
090	            }
091	            <commands> {
092	                    <name> "file copy /var/tmp/baseline-info.tgz ftp://usrname:password@remote-machine//var/tmp/baseline-info.tgz";
093	            }
094	            <output-format> "text";
095	            }
096	        }
097	        }
098	    }
099	    }
100	 
101	match / {
102	}
XML Script Contents

 

01	<?xml version="1.0"?>
02	<script>
03	  <title>baseline-info.slax</title>
04	  <author>rsankar</author>
05	  <synopsis>
06	    Event-based script to automatically save and offload support information
07	  </synopsis>
08	  <coe>event</coe>
09	  <type>support</type>
10	 
11	  <description>
12	Saving a current view of the system using the "request support info" command immediately following the event will save time and effort in resolving incidents.
13	Additionally, copying this information plus log files and core dump files to a management server will streamline the effort to provide basic information in the event that a TAC case needs to be opened.
14	 
15	  </description>
16	 
17	  <keyword>support</keyword>
18	  <example>
19	    <title>Configuration</title>
20	    <description>Configuration required for this event script.</description>
21	    <config>example-1.conf</config>
22	  </example>
23	 
24	  <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
25	                src="../../../../../web/leaf.js"
26	            type="text/javascript"/>
27	</script>