1+ <?php
2+
3+ function getJSONfromURL ($ url ){
4+ $ curl = curl_init ();
5+ curl_setopt ($ curl , CURLOPT_URL , $ url );
6+ curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
7+ $ result = curl_exec ($ curl );
8+ curl_close ($ curl );
9+ $ json = json_decode ($ result , true );
10+ return $ json ;
11+ }
12+
13+
14+ function getXMLfromURL ($ url ){
15+ $ curl = curl_init ();
16+ curl_setopt ($ curl , CURLOPT_URL , $ url );
17+ curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
18+ $ xml = curl_exec ($ curl );
19+ curl_close ($ curl );
20+ return $ xml ;
21+ }
22+
23+
24+ function getMessage ($ hostName ){
25+ error_reporting (0 );
26+ $ url = "http://dashb-cms-sum.cern.ch/dashboard/request.py/getTestResults?profile_name=CMS_CRITICAL_FULL&hostname= " . $ hostName . "&flavours=CREAM-CE,SRMv2&metrics=org.cms.glexec.WN-gLExec,org.cms.glexec.WN-gLExec,org.cms.glexec.WN-gLExec,org.cms.glexec.WN-gLExec&time_range=last12&start_time=undefined&end_time=undefined " ;
27+ $ json = getJSONfromURL ($ url );
28+ $ warningID = array ();
29+ $ okID = array ();
30+ $ errorID = array ();
31+ foreach ($ json ["data " ] as $ key => $ value ){
32+ foreach ($ value as $ keyy => $ valuee ){
33+ foreach ($ valuee as $ keyyy => $ valueee ) {
34+ if (strstr ($ valueee [1 ], "OK " )){
35+ $ okID [] = $ valueee [0 ];
36+ }else {
37+ $ warningID [] = $ valueee [0 ];
38+ } // if OK or WARNING
39+ } // foreach valueee
40+ } // foreach valuee
41+ } // foreach value
42+ foreach ($ json ["urls " ] as $ urlKey => $ urlValue ){
43+ foreach ($ urlValue as $ urlChildKey => $ urlChildValue ){
44+ if (in_array ($ urlChildKey , $ warningID )){
45+ $ xml = getXMLfromURL ("http://dashb-cms-sum.cern.ch/dashboard/request.py/ " . $ urlChildValue );
46+ $ logOnlyMode = "Warning: Same /usr/bin/id for payload and pilot " ;
47+ if (!strstr ($ xml , $ logOnlyMode )){
48+ $ errorID [$ urlChildKey ] = "http://dashb-cms-sum.cern.ch/dashboard/request.py/ " . $ urlChildValue ;
49+ } // if logOnlyMode
50+ } // if in_array warningID
51+ } // foreach urlValue
52+ }
53+ return array ($ errorID , $ okID );
54+ } // function getMessage
55+
56+
57+ function getAllCE (){
58+ $ countTotalSite = 0 ;
59+ $ data = getXMLfromURL ("http://grid-monitoring.cern.ch/myegi/sam-pi/latest_metric_results_in_profile/?vo_name=cms&profile_name=CMS_CRITICAL_FULL&service_hostname=&service_flavour=CREAM-CE " );
60+ $ xml = simplexml_load_string ($ data );
61+ $ siteList = array ();
62+ $ glexecList = array ();
63+ $ countT1s = 0 ;
64+ $ countT2s = 0 ;
65+ foreach ($ xml ->Profile ->Group as $ site ){
66+ $ countTotalSite ++;
67+ $ siteName = (string )$ site ["name " ];
68+ if (substr ($ siteName , 0 ,2 ) == 'T1 ' ) {$ countT1s ++;}
69+ if (substr ($ siteName , 0 ,2 ) == 'T2 ' ) {$ countT2s ++;}
70+ $ countService = count ($ site ->Service );
71+ if ($ countService > 0 ){
72+ for ($ j =0 ; $ j < $ countService ; $ j ++) {
73+ if ($ site ->Service [$ j ]->Metric ){
74+ $ countMtr = count ($ site ->Service [$ j ]->Metric );
75+ $ hostName = (string )$ site ->Service [$ j ]['hostname ' ];
76+ @$ siteList [$ siteName ][] = $ hostName ;
77+ } // if site->Services->Metric
78+ } // for services
79+ //echo "<hr>";
80+ } // for countServices
81+ } // site foreach
82+ ksort ($ siteList );
83+ return array ($ siteList , $ countT1s , $ countT2s );
84+ } //function getAllCE
85+
86+
87+ function getGLEXEC ($ siteList ){
88+ $ countT1sProblem = 0 ;
89+ $ countT2sProblem = 0 ;
90+ $ siteFlag = '' ;
91+ foreach ($ siteList as $ siteName => $ hostName ){
92+ if ((substr ($ siteName , 0 ,2 ) == 'T1 ' ) || (substr ($ siteName , 0 ,2 ) == 'T2 ' )){
93+ foreach ($ hostName as $ hostKey ){
94+ list ($ errorID , $ okID ) = getMessage ($ hostKey );
95+ if (!(empty ($ errorID )) || !(empty ($ okID ))){
96+ if (count ($ errorID ) >= count ($ okID )){
97+ $ dashboardUrl = "http://dashb-cms-sum.cern.ch/dashboard/request.py/historicalsmryview-sum#view=test&time%5B%5D=last12&granularity%5B%5D=default&profile=CMS_CRITICAL_FULL&group=AllGroups&site%5B%5D= "
98+ . $ siteName
99+ . "&flavour%5B%5D=All+Service+Flavours&disabledFlavours=true&metric%5B%5D=org.cms.glexec.WN-gLExec&metric%5B%5D=org.cms.glexec.WN-gLExec&metric%5B%5D=org.cms.glexec.WN-gLExec&metric%5B%5D=org.cms.glexec.WN-gLExec&disabledMetrics=true&host%5B%5D= "
100+ . $ hostKey ;
101+ $ glexecList [$ siteName ][$ hostKey ] = $ dashboardUrl ;
102+ if ($ siteFlag != $ siteName ){
103+ if (substr ($ siteName , 0 ,2 ) == 'T1 ' ) {$ countT1sProblem ++;}
104+ if (substr ($ siteName , 0 ,2 ) == 'T2 ' ) {$ countT2sProblem ++;}
105+ $ siteFlag = $ siteName ;
106+ }
107+ }}
108+ } // foreeach hostName
109+ } // if siteName T1 or T2
110+ } // foreach siteList
111+ return array ($ glexecList , $ countT1sProblem , $ countT2sProblem );
112+ }
113+ ?>
0 commit comments