![]() | ![]() | ![]() | ![]() |
This coding approach demonstrates how to use SAS to detect UNIX and Windows server response anomalies, and then notify key personnel by email and cell phone text messages. The crux of this approach is the PING command. PING is a diagnostic command line statement used to assess if a given server is active on the network.
The added value of using this approach is six-fold:
The following example demonstrates how to:
This example assumes that a UNIX server with a SAS V8.2 or later installation executes the PING application to check the 'vital signs' of three other UNIX servers. The script may need to be modified based upon the configuration of other UNIX servers. For each of the servers, the application is executed 47 times for 23.5 consecutive hours; 30 minutes are left open to ensure that the application completes cleanly before restarting.
This example is general - you will have to adjust or add code to customize:
If you send a notification to someone with cell phone, be sure that the recipient's text messaging services are operable and that you have the correct Vendor-specific syntax. The cell phone syntax in the example is not applicable for all vendors.
The reply from UNIX PING command may return a different reply than the Windows PING command. You will have to test this manually at the UNIX and WINDOWS command prompts to determine if the 'active' replies are the same. If the replies are different, then you will have to add code if you want to check UNIX and Windows servers within the same application.
![]()
About the Author
Bryan K. Beverly is a Software Architect and Team Leader with BAE Systems Information Technology. He has been using SAS for 20+ years and is currently supporting SAS-based systems at the Bureau of Labor Statistics. Bryan has served as a presenter and volunteer at SAS conferences for more than 10 years.
/**********************************************************************/
%macro server;
/****************************************************/
/*initialize the environment before processing */
/* - not essential but a good housekeeping practice */
/****************************************************/
filename _all_ clear; /*remove existing filename allocations*/
libname _all_ clear; /*remove existing libname allocations*/
ods html close; /*close ODS if a prior job left it open*/
proc datasets kill nolist; /*delete existing temporary data sets*/
run;
quit;
%macro ping(server=, /*name of server*/
prim=, /*primary recipient*/
cc1=, /*secondary recipient*/
cc2=); /*tertiary recipient*/
/*delete the prior file that stored server status information*/
x "rm -f /your/utility_jobs/server_status.dat";
/*PING the server and pipe the status information into a text file*/
x "ping &server>/your/utility_jobs/server_status.dat";
/*allocate the text file as an input source*/
filename server "/your/utility_jobs/server_status.dat";
/*read the status data into a temporary file and capture the status*/
data server_chk;
length servstat $ 70 status $ 5;
infile server pad missover lrecl=70;
input @1 servstat $char70.;
status=scan(servstat,3);
run;
/*macro captures general metadata, including the number of observations*/
/* - for this application, there should only be 1 observation*/
%macro metadata(ds);
%global dset nvars nobs;
%let dset = &ds;
%let dsid = %sysfunc(open(&dset));
%let nobs = %sysfunc(attrn(&dsid,NOBS));
%let nvars = %sysfunc(attrn(&dsid,NVARS));
%let rc = %sysfunc(close(&dsid));
%mend metadata;
%metadata(server_chk);
/*store the status as a macro variable*/
data _null_;
set server_chk;
if _N_ = &nobs;
call symput('status',status);
run;
%if &status ^= alive %then %do;
/*send email and a cell phone text messages*/
data _null_;
filename outbox email "&prim" ;
file outbox
cc=("&cc1","&cc2")
subject="Please Check &server Immediately";
put "a PING of &server detected a problem.";
run;
%end;
%mend ping;
%macro timer;
%do i=1 %to 47; /*perform for 23.5 hours*/
%ping(server=SERVER_NAME1,
prim=SOMEBODY@usa.gov,
cc1=111CELLPHONE1@messaging.nextel.com,
cc2=111CELLPHONE2@messaging.nextel.com);
%ping(server=SERVER_NAME2,
prim=SOMEBODY@usa.gov,
cc1=222CELLPHONE1@messaging.nextel.com,
cc2=222CELLPHONE2@messaging.nextel.com);
%ping(server=SERVER_NAME3,
prim=SOMEBODY@usa.gov,
cc1=333CELLPHONE1@messaging.nextel.com,
cc2=333CELLPHONE2@messaging.nextel.com);
data _null_; /*suspend SAS for 30 minutes*/
snooze=sleep(1800*1000); /*time is in milli-seconds on UNIX servers*/
run; /*time is in seconds on Windows servers*/
%end;
%mend timer;
%timer;
/***************************************************/
/*clean up everything and reset the default options*/
/***************************************************/
libname _all_ clear;
filename _all_ clear;
proc datasets kill nolist;
run;
quit;
%mend server;
%server;| Type: | Sample |
| Topic: | Non SAS Authors ==> Bryan K. Beverly |
| Date Modified: | 2005-11-08 03:03:20 |
| Date Created: | 2005-11-07 11:23:00 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | Tru64 UNIX | 8.2 TS2M0 | n/a |
| Solaris | 8.2 TS2M0 | n/a | ||
| Linux | 8.2 TS2M0 | n/a | ||
| HP-UX IPF | 8.2 TS2M0 | n/a | ||
| HP-UX | 8.2 TS2M0 | n/a | ||
| ABI+ for Intel Architecture | 8.2 TS2M0 | n/a | ||
| AIX | 8.2 TS2M0 | n/a | ||
| 64-bit Enabled Solaris | 8.2 TS2M0 | n/a | ||
| 64-bit Enabled AIX | 8.2 TS2M0 | n/a | ||
| 64-bit Enabled HP-UX | 8.2 TS2M0 | n/a | ||




