/* ** Copyright © 2007 SAS Institute Inc., ** SAS Campus Drive, Cary, North Carolina 27513, USA. All rights reserved. ** ** Refer to the Terms of Use and Legal Information on: http://www.sas.com/Copyright.html ** ** HobbitAutoConfig.sas ** Version 1.1 ** ** This SAS file will probe the specified SAS Metadata Server to discover the ** local SAS BI configuration hierarchy and will then use that data to generate ** monitoring configuration files for Hobbit. ** ** Change the "options" below to match your SAS Metadata server. If you run this ** SAS program as an interactive session, you may leave the "metapass" password ** as NULL and SAS will display a popup window allowing you to enter that field. */ options metaserver="metadata.node.domain.name" metaport=8561 metaprotocol="bridge" metapass="" metarepository="Foundation"; data _null_; array machine[100,2] $200; /* column 1=name, 2=uri) */ array tiers[100,3]; /* indicate SAS BI tiers - row dimension as "machine" */ /* flags column 1=server, 2=mid, 3=client */ length uri $256; length uri2 $256; length uri3 $256; length name $200; length desc $200; length myserver $200; length myrepos $200; length name $200; length port $200; length prodname $200; /* count of machines found for each SAS BI tier */ server_tier=0; mid_tier=0; client_tier=0; no_tier=0; myday=today(); nobj=0; n=1; uri=""; name=""; desc=""; /* ** Get working copies of these SAS options. Note that if the metaserver, ** metaport, or metarepository are changed in the interactive dialog window, ** those new values will NOT be properly reflected here, which could cause ** confusion since the comments in the output file will use the values defined ** in the options statement above. */ myserver=getoption('metaserver'); myport=getoption('metaport'); myrepos=getoption('metarepository'); nobj=metadata_getnobj("omsobj:Machine?@Id contains '.'",n,uri); if nobj = -1 then do; put 'Couldn''t connect to specified SAS Metadata Server.'; put 'Was your user/password correct?'; stop; end; nmax=dim1(machine); /* sanity check */ if nobj > nmax then do; put 'More than the limit of ' nmax 'machines found in the metadata BI hierarchy.'; put 'Increase the size of the machine and tiers arrays to at least ' nobj 'and re-run.'; stop; end; tmax=dim1(tiers); /* sanity check */ if tmax ^= nmax then do; put 'The tiers and machine arrays must have the same first dimension. Check your'; put 'size modifications and re-run.'; stop; end; /* ** To generate the Hobbit bb-hosts file, we need to first create an intermediate ** listing of the machines in the SAS Metadata hierarchy, then post-process that list ** to handle grouping into server tiers, etc., which isn't easy to do within a ** SAS data step. */ do while (n <= nobj); nobj=metadata_getnobj("omsobj:Machine?@Id contains '.'",n,uri); rc=metadata_getattr(uri,"Name",name); machine[n,1]=name; machine[n,2]=uri; tiers[n,1]=0; /* SAS BI tier flag */ tiers[n,2]=0; tiers[n,3]=0; n=n+1; end; /* ** Phase 2, generate a Hobbit clients configuration file. The resulting file ** can be added to the mai Hobbit clients file via the Hobbit "include" operator, ** or if partial definitions for the related machines already exist there, the ** relevant SAS configuration lines can be cut/pasted into that main configuration ** file. */ file 'hobbit-clients-sas-bi.cfg'; /* */ put '######################################################################################'; put '#'; put '# hobbit-clients-sas-bi.cfg'; put '#'; put '# This configuration file was automatically generated on ' myday worddate. ' from'; put '# the SAS BI server definitions in the ' myrepos 'repository of the'; put '# SAS Metadata Server on machine ' myserver +(-1) ':' myport; put '#'; put '# There are ' nobj 'machines to monitor in this configuration.'; put '#'; put '# Use the Hobbit "include" operator to include this file in the main'; put '# "/etc/hobbit-clients.cfg" configuration file on the Hobbit server machine.'; put '# If you already define some of the described machines in that file, either comment out'; put '# these instances or cut-paste the additional machine definitions into'; put '# "/etc/hobbit-config" instead of including this file.'; put '#'; put '# For Unix hosts, you may want to uncomment the "FILE" lines to track system messages.'; put '######################################################################################'; put; put; n=1; uri=""; do while (n <= nobj); name=machine[n,1]; uri=machine[n,2]; put 'HOST=' name; put ' # For Unix hosts uncomment the following line'; put ' #FILE /var/adm/messages SIZE>0 TRACK'; put; put ' UP 30m'; put ' LOAD 70 80'; put ' PROC hobbitlaunch 1 1 yellow'; if name=myserver then do; put ' PORT LOCAL=%[\.:]' myport ' STATE=LISTEN min=1 "TEXT=SAS Metadata Server:' myport +(-1) '"'; tiers[n,1] = 1; /* server tier */ end; /* ** Now we have to descend through the metadata hierarchy to eventually get to the TCPIP ** connection data for each Machine service. The hierarchy of objects, properties, and ** associations goes something like this: ** ** Machine ** DeployedComponents ** ServerComponent ** SourceConnection ** TCPIPConnection ** Port ** ** Each of the above could have multiple instances, each with associated multiple children. ** **** ** We have a Machine. ** See how many (if any) DeployedComponents are associated with this Machine. */ i=1; uri2=""; num_components=0; num_components=metadata_getnasn(uri,"DeployedComponents",i,uri2); /*** put 'DeployedComponents=' num_components ' uri=' uri; /* DEBUG */ /* ** If this Machine has DeployedComponents, scan through each of them to see if ** the component is a ServerComponent. */ if num_components > 0 then do; i=1; do while (i <= num_components); uri2=""; rc=metadata_getnasn(uri,"DeployedComponents",i,uri2); /* ** If this is a ServerComponent, tag the machine with the SAS server tier(s) it belongs to. */ if rc > 0 & uri2=:"OMSOBJ:ServerComponent\" then do; /*** put ' uri2=' uri2; /* DEBUG */ prodname=""; rc=metadata_getattr(uri2,"ProductName",prodname); if rc = 0 then do; /* ** Yes, this is an ugly brute-force comparison, but it is expedient and obvious. */ /*** put prodname=; /* DEBUG */ if prodname="SAS Workspace" | prodname="SAS Stored Process" | prodname="SAS OLAP Server" | prodname="SAS Workspace Spawner" | prodname="SAS/CONNECT" | prodname="REMOTE" then do; tiers[n,1] = 1; /* server tier */ server_tier = server_tier + 1; end; if prodname="Http Server" then do; tiers[n,2] = 1; /* mid tier */ mid_tier = mid_tier + 1; end; end; j=1; uri3=""; num_sourceconn=0; num_sourceconn=metadata_getnasn(uri2,"SourceConnections",j,uri3); /* ** If there are SourceConnections, get the related TCPIPConnection object ** and fetch the Port to monitor and the Name. */ if num_sourceconn > 0 then do; j=1; do while (j <= num_sourceconn); uri3=""; rc=metadata_getnasn(uri2,"SourceConnections",j,uri3); /*** put ' uri3=' uri3 ' rc=' rc; /* DEBUG */ /* ** For now, only TCPIPConnection types will be configured for Hobbit. ** ** Fetch the Port and Name so we can build a Hobbit "PORT" definition. */ if uri3=:"OMSOBJ:TCPIPConnection\" then do; name=""; port=""; rc=metadata_getattr(uri3,"Name",name); rc=metadata_getattr(uri3,"Port",myport); put ' PORT LOCAL=%[\.:]' myport ' STATE=LISTEN min=1 "TEXT=' name ':' myport +(-1) '"'; end; j=j+1; end; end; end; i=i+1; end; end; /**** put 'SAS BI tiers=' tiers[n,1] tiers[n,2] tiers[n,3]; /* DEBUG */ n=n+1; put; end; put; put '# End of file'; /* ** Now generate the bb-hosts file based on teh accumulatd machine and tier data. ** We make five passes through the data, writing out the server tiers separately. ** The tiers can be server, mid, cleint, multi, and unassigned. */ file 'bb-hosts-sas-bi'; /* */ put '#####################################################################################'; put '#'; put '# bb-hosts-sas-bi'; put '#'; put '# This configuration file was automatically generated on ' myday worddate. ' from'; put '# the SAS BI server definitions in the ' myrepos 'repository of the'; put '# SAS Metadata Server on machine ' myserver +(-1) ':' myport; put '#'; put '# There are ' nobj 'machines to monitor in this configuration.'; put '#'; put '# You will need to change the "nn.nn.nn.nn" entries to reflect the IP addresses'; put '# for the related machine definitions.'; put '#'; put '# Use the Hobbit "include" operator to include this file in the main "/etc/bb-hosts"'; put '# configuration file on the Hobbit server machine. If you already define some of the'; put '# described machines in that file, either comment out these instances or cut-paste'; put '# the additional machine definitions into "/etc/bb-hosts" instead of including'; put '# this file.'; put '#####################################################################################'; put; put; put 'page sas_ebi_servers SAS EBI Servers'; /* ** Some machines may support servers from multiple SAS BI tiers. ** Some product names may not have been recognized, so assign those uses to "no_tier". */ multi_tier=0; no_tier=0; n=1; do while (n < nobj); if (tiers[n,1] + tiers[n,2] + tiers[n,3]) > 1 then multi_tier=multi_tier+1; if (tiers[n,1] + tiers[n,2] + tiers[n,3]) = 0 then no_tier=no_tier+1; n=n+1; end; /* ** Server tier. */ n=1; if server_tier > 0 then do; put 'group Server Tier'; do while (n <= nobj); if (tiers[n,1] = 1) & ((tiers[n,2] + tiers[n,3]) = 0) then do; dot = index(machine[n,1], "."); if dot > 0 then do; name = UPCASE(substr(machine[n,1], 1, dot-1)); put 'nn.nn.nn.nn ' machine[n,1] ' # NAME:"' name +(-1) '"'; end; end; n=n+1; end; /* do while */ put; end; /* if server_tier */ /* ** Mid tier. */ n=1; if mid_tier > 0 then do; put 'group Mid Tier'; do while (n <= nobj); if (tiers[n,2] = 1) & ((tiers[n,1] + tiers[n,3]) = 0) then do; dot = index(machine[n,1], "."); if dot > 0 then do; name = UPCASE(substr(machine[n,1], 1, dot-1)); put 'nn.nn.nn.nn ' machine[n,1] ' # NAME:"' name +(-1) '"'; end; end; n=n+1; end; /* do while */ put; end; /* if mid_tier */ /* ** Client tier. */ n=1; if client_tier > 0 then do; put 'group Client Tier'; do while (n <= nobj); if (tiers[n,3] = 1) & ((tiers[n,1] + tiers[n,2]) = 0) then do; dot = index(machine[n,1], "."); if dot > 0 then do; name = UPCASE(substr(machine[n,1], 1, dot-1)); put 'nn.nn.nn.nn ' machine[n,1] ' # NAME:"' name +(-1) '"'; end; end; n=n+1; end; /* do while */ put; end; /* if client_tier */ /* ** Multi tier. */ n=1; if multi_tier > 0 then do; put 'group Multiple Tiers'; do while (n <= nobj); if ((tiers[n,1] + tiers[n,2] + tiers[n,3]) > 1) then do; dot = index(machine[n,1], "."); if dot > 0 then do; name = UPCASE(substr(machine[n,1], 1, dot-1)); put 'nn.nn.nn.nn ' machine[n,1] ' # NAME:"' name +(-1) '"'; end; end; n=n+1; end; /* do while */ put; end; /* if multi_tier */ /* ** Unassigned tier. */ n=1; if no_tier > 0 then do; put 'group Unassigned Tiers'; do while (n <= nobj); if ((tiers[n,1] + tiers[n,2] + tiers[n,3]) = 0) then do; dot = index(machine[n,1], "."); if dot > 0 then do; name = UPCASE(substr(machine[n,1], 1, dot-1)); put 'nn.nn.nn.nn ' machine[n,1] ' # NAME:"' name +(-1) '"'; end; end; n=n+1; end; /* do while */ put; end; /* if no_tier */ put '# End of file'; run; /* ** Copyright © 2007 SAS Institute Inc., ** SAS Campus Drive, Cary, North Carolina 27513, USA. All rights reserved. ** */