root/trunk/tdatacenterfunc.h

Revision 1860, 24.9 KB (checked in by Dylan, 4 months ago)

unxsVZ minor extensions to datacenter and container tabs.

  • Property svn:keywords set to id
Line 
1/*
2FILE
3        $Id$
4        (Built initially by unixservice.com mysqlRAD2)
5PURPOSE
6        Non schema-dependent table and application table related functions.
7AUTHOR
8        (C) 2001-2009 Unixservice, LLC.
9*/
10
11static unsigned uClone=0;
12static unsigned uOldDatacenter=0;
13static unsigned uTargetNode=0;
14static char cuTargetNodePullDown[256]={""};
15
16//ModuleFunctionProtos()
17void tDatacenterNavList(void);
18void tDatacenterHealth(void);
19
20//tnodefunc.h
21void CopyProperties(unsigned uOldNode,unsigned uNewNode,unsigned uType);
22void DelProperties(unsigned uNode,unsigned uType);
23void tNodeNavList(unsigned uDataCenter);
24
25//tgroupfunc.h
26void tGroupNavList(void);
27
28//tcontainerfunc.h
29char *cRatioColor(float *fRatio);
30
31//tclientfunc.h
32static unsigned uForClient=0;
33static char cForClientPullDown[256]={"---"};
34
35void ExtProcesstDatacenterVars(pentry entries[], int x)
36{
37        register int i;
38        for(i=0;i<x;i++)
39        {
40                if(!strcmp(entries[i].name,"uClone"))
41                        uClone=1;
42                else if(!strcmp(entries[i].name,"cForClientPullDown"))
43                {
44                        strcpy(cForClientPullDown,entries[i].val);
45                        uForClient=ReadPullDown(TCLIENT,"cLabel",cForClientPullDown);
46                }
47                else if(!strcmp(entries[i].name,"cuTargetNodePullDown"))
48                {
49                        sprintf(cuTargetNodePullDown,"%.255s",entries[i].val);
50                        uTargetNode=ReadPullDown("tNode","cLabel",cuTargetNodePullDown);
51                }
52        }
53}//void ExtProcesstDatacenterVars(pentry entries[], int x)
54
55
56void ExttDatacenterCommands(pentry entries[], int x)
57{
58
59        if(!strcmp(gcFunction,"tDatacenterTools"))
60        {
61                MYSQL_RES *res;
62                time_t uActualModDate= -1;
63
64                if(!strcmp(gcCommand,LANG_NB_NEW))
65                {
66                        if(guPermLevel>=9)
67                        {
68                                uOldDatacenter=uDatacenter;
69                                ProcesstDatacenterVars(entries,x);
70                                guMode=2000;
71                                tDatacenter(LANG_NB_CONFIRMNEW);
72                        }
73                }
74                else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW))
75                {
76                        if(guPermLevel>=9)
77                        {
78                                ProcesstDatacenterVars(entries,x);
79                                uOldDatacenter=uDatacenter;
80
81                                guMode=2000;
82                                //Check entries here
83                                if(strlen(cLabel)<3)
84                                        tDatacenter("<blink>Error</blink>: Must supply valid cLabel. Min 3 chars.");
85                                sprintf(gcQuery,"SELECT uDatacenter FROM tDatacenter WHERE cLabel='%s'",
86                                                cLabel);
87                                mysql_query(&gMysql,gcQuery);
88                                if(mysql_errno(&gMysql))
89                                                htmlPlainTextError(mysql_error(&gMysql));
90                                res=mysql_store_result(&gMysql);
91                                if(mysql_num_rows(res))
92                                {
93                                        mysql_free_result(res);
94                                        tDatacenter("<blink>Error</blink>: Datacenter cLabel is used!");
95                                }
96                                guMode=0;
97
98                                if(!uForClient)
99                                        uOwner=guCompany;
100                                else
101                                        uOwner=uForClient;
102                                uDatacenter=0;
103                                uCreatedBy=guLoginClient;
104                                //GetClientOwner(guLoginClient,&guReseller);
105                                //uOwner=guReseller;
106                                uModBy=0;//Never modified
107                                uModDate=0;//Never modified
108                                uStatus=1;//Active
109                                NewtDatacenter(1);
110                                sprintf(gcQuery,"INSERT INTO tProperty SET uKey=%u,uType=1"
111                                                ",cName='Contact',uOwner=%u,uCreatedBy=%u"
112                                                ",uCreatedDate=UNIX_TIMESTAMP(NOW())"
113                                                        ,uDatacenter,guCompany,guLoginClient);
114                                mysql_query(&gMysql,gcQuery);
115                                if(mysql_errno(&gMysql))
116                                                htmlPlainTextError(mysql_error(&gMysql));
117                                if(uDatacenter && uOldDatacenter && uClone)
118                                        CopyProperties(uOldDatacenter,uDatacenter,1);
119                                if(uDatacenter)
120                                        tDatacenter("New datacenter created");
121                                else
122                                        tDatacenter("<blink>Error</blink>: Datacenter not created!");
123                        }
124                }
125                else if(!strcmp(gcCommand,LANG_NB_DELETE))
126                {
127                        ProcesstDatacenterVars(entries,x);
128                        if(uAllowDel(uOwner,uCreatedBy))
129                        {
130                                guMode=0;
131                                sscanf(ForeignKey("tDatacenter","uModDate",uDatacenter),"%lu",&uActualModDate);
132                                if(uModDate!=uActualModDate)
133                                        tDatacenter("<blink>Error</blink>: This record was modified. Reload it.");
134                                sprintf(gcQuery,"SELECT uDatacenter FROM tContainer WHERE uDatacenter=%u",
135                                                                        uDatacenter);
136                                mysql_query(&gMysql,gcQuery);
137                                if(mysql_errno(&gMysql))
138                                                htmlPlainTextError(mysql_error(&gMysql));
139                                res=mysql_store_result(&gMysql);
140                                if(mysql_num_rows(res))
141                                {
142                                        mysql_free_result(res);
143                                        tDatacenter("<blink>Error</blink>: Can't delete a datacenter"
144                                                        " used by a container!");
145                                }
146                                guMode=2001;
147                                tDatacenter(LANG_NB_CONFIRMDEL);
148                        }
149                        else
150                                tDatacenter("<blink>Error</blink>: Denied by permissions settings");
151                }
152                else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL))
153                {
154                        ProcesstDatacenterVars(entries,x);
155                        if(uAllowDel(uOwner,uCreatedBy))
156                        {
157                                guMode=5;
158                                sscanf(ForeignKey("tDatacenter","uModDate",uDatacenter),"%lu",&uActualModDate);
159                                if(uModDate!=uActualModDate)
160                                        tDatacenter("<blink>Error</blink>: This record was modified. Reload it.");
161                                sprintf(gcQuery,"SELECT uDatacenter FROM tContainer WHERE uDatacenter=%u",
162                                                                        uDatacenter);
163                                mysql_query(&gMysql,gcQuery);
164                                if(mysql_errno(&gMysql))
165                                                htmlPlainTextError(mysql_error(&gMysql));
166                                res=mysql_store_result(&gMysql);
167                                if(mysql_num_rows(res))
168                                {
169                                        mysql_free_result(res);
170                                        tDatacenter("<blink>Error</blink>: Can't delete a datacenter"
171                                                        " used by a container!");
172                                }
173                                guMode=0;
174                                DelProperties(uDatacenter,2);
175                                DeletetDatacenter();
176                        }
177                        else
178                                tDatacenter("<blink>Error</blink>: Denied by permissions settings");
179                }
180                else if(!strcmp(gcCommand,LANG_NB_MODIFY))
181                {
182                        ProcesstDatacenterVars(entries,x);
183                        if(uAllowMod(uOwner,uCreatedBy))
184                        {
185
186                                guMode=2002;
187                                tDatacenter(LANG_NB_CONFIRMMOD);
188                        }
189                        else
190                                tDatacenter("<blink>Error</blink>: Denied by permissions settings");
191                }
192                else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD))
193                {
194                        ProcesstDatacenterVars(entries,x);
195                        if(uAllowMod(uOwner,uCreatedBy))
196                        {
197                                guMode=2002;
198                                //Check entries here
199                                if(strlen(cLabel)<3)
200                                        tDatacenter("<blink>Error</blink>: Must supply valid cLabel. Min 3 chars.");
201                                guMode=0;
202
203                                uModBy=guLoginClient;
204                                if(uForClient)
205                                {
206                                        sprintf(gcQuery,"UPDATE tDatacenter SET uOwner=%u WHERE uDatacenter=%u",
207                                                uForClient,uDatacenter);
208                                        mysql_query(&gMysql,gcQuery);
209                                        if(mysql_errno(&gMysql))
210                                                htmlPlainTextError(mysql_error(&gMysql));
211                                        uOwner=uForClient;
212                                }
213                                ModtDatacenter();
214                        }
215                        else
216                                tDatacenter("<blink>Error</blink>: Denied by permissions settings");
217                }
218        }
219
220}//void ExttDatacenterCommands(pentry entries[], int x)
221
222
223void ExttDatacenterButtons(void)
224{
225        OpenFieldSet("tDatacenter Aux Panel",100);
226        switch(guMode)
227        {
228                case 2000:
229                        printf("<p><u>Enter/mod data</u><br>");
230                        printf(LANG_NBB_CONFIRMNEW);
231                        if(uOldDatacenter)
232                                printf("<p>Copy properties <input title='Copies all properties'"
233                                        " type=checkbox name=uClone checked>\n");
234                        if(guPermLevel>11)
235                                tTablePullDownResellers(uForClient,1);
236                break;
237
238                case 2001:
239                        printf("<p><u>Think twice</u><br>");
240                        printf(LANG_NBB_CONFIRMDEL);
241                break;
242
243                case 2002:
244                        printf("<p><u>Review changes</u><br>");
245                        printf(LANG_NBB_CONFIRMMOD);
246                        if(guPermLevel>11)
247                        {
248                                printf("<p>You change the record owner, just...");
249                                tTablePullDownResellers(guCompany,1);
250                        }
251                break;
252
253                default:
254                        printf("<u>Table Tips</u><br>");
255                        printf("A datacenter is a collection of hardware nodes."
256                                        " These hardware nodes need not be located in the same"
257                                        " physical datacenter. Hardware nodes host VZ containers."
258                                        " It is in these containers that actual public services run."
259                                        " uVeth='Yes' container traffic is not included"
260                                        "in the datacenter graphs at this time.");
261                        tGroupNavList();
262                        tNodeNavList(uDatacenter);
263                        tDatacenterNavList();
264                        tDatacenterHealth();
265        }
266        CloseFieldSet();
267
268}//void ExttDatacenterButtons(void)
269
270
271void ExttDatacenterAuxTable(void)
272{
273        if(!uDatacenter || guMode==2000 )//uMODE_NEW
274                return;
275
276        MYSQL_RES *res;
277        MYSQL_ROW field;
278
279        sprintf(gcQuery,"%s Property Panel",cLabel);
280        OpenFieldSet(gcQuery,100);
281        sprintf(gcQuery,"SELECT uProperty,cName,cValue FROM tProperty WHERE uKey=%u AND uType="PROP_DATACENTER
282                        " ORDER BY cName",uDatacenter);
283
284        mysql_query(&gMysql,gcQuery);
285        if(mysql_errno(&gMysql))
286                htmlPlainTextError(mysql_error(&gMysql));
287
288        res=mysql_store_result(&gMysql);
289        if(mysql_num_rows(res))
290        {
291                printf("<table cols=2>");
292                while((field=mysql_fetch_row(res)))
293                {
294                        printf("<tr>\n");
295                        printf("<td width=200 valign=top><a class=darkLink href=unxsVZ.cgi?"
296                                        "gcFunction=tProperty&uProperty=%s&cReturn=tDatacenter_%u>"
297                                        "%s</a></td><td valign=top><pre>%s</pre></td>\n",
298                                                field[0],uDatacenter,field[1],field[2]);
299                        printf("</tr>\n");
300                }
301                printf("</table>");
302        }
303
304        CloseFieldSet();
305
306}//void ExttDatacenterAuxTable(void)
307
308
309void ExttDatacenterGetHook(entry gentries[], int x)
310{
311        register int i;
312
313        for(i=0;i<x;i++)
314        {
315                if(!strcmp(gentries[i].name,"uDatacenter"))
316                {
317                        sscanf(gentries[i].val,"%u",&uDatacenter);
318                        guMode=6;
319                }
320        }
321        tDatacenter("");
322
323}//void ExttDatacenterGetHook(entry gentries[], int x)
324
325
326void ExttDatacenterSelect(void)
327{
328        ExtSelect("tDatacenter",VAR_LIST_tDatacenter);
329
330}//void ExttDatacenterSelect(void)
331
332
333void ExttDatacenterSelectRow(void)
334{
335        ExtSelectRow("tDatacenter",VAR_LIST_tDatacenter,uDatacenter);
336
337}//void ExttDatacenterSelectRow(void)
338
339
340void ExttDatacenterListSelect(void)
341{
342        char cCat[512];
343
344        ExtListSelect("tDatacenter",VAR_LIST_tDatacenter);
345
346        //Changes here must be reflected below in ExttDatacenterListFilter()
347        if(!strcmp(gcFilter,"uDatacenter"))
348        {
349                sscanf(gcCommand,"%u",&uDatacenter);
350                if(guPermLevel<10)
351                        strcat(gcQuery," AND ");
352                else
353                        strcat(gcQuery," WHERE ");
354                sprintf(cCat,"tDatacenter.uDatacenter=%u ORDER BY uDatacenter",uDatacenter);
355                strcat(gcQuery,cCat);
356        }
357        else if(1)
358        {
359                //None NO FILTER
360                strcpy(gcFilter,"None");
361                strcat(gcQuery," ORDER BY uDatacenter");
362        }
363
364}//void ExttDatacenterListSelect(void)
365
366
367void ExttDatacenterListFilter(void)
368{
369        //Filter
370        printf("&nbsp;&nbsp;&nbsp;Filter on ");
371        printf("<select name=gcFilter>");
372        if(strcmp(gcFilter,"uDatacenter"))
373                printf("<option>uDatacenter</option>");
374        else
375                printf("<option selected>uDatacenter</option>");
376        if(strcmp(gcFilter,"None"))
377                printf("<option>None</option>");
378        else
379                printf("<option selected>None</option>");
380        printf("</select>");
381
382}//void ExttDatacenterListFilter(void)
383
384
385void ExttDatacenterNavBar(void)
386{
387        printf(LANG_NBB_SKIPFIRST);
388        printf(LANG_NBB_SKIPBACK);
389        printf(LANG_NBB_SEARCH);
390
391        if(guPermLevel>=9 && !guListMode)
392                printf(LANG_NBB_NEW);
393
394        if(uAllowMod(uOwner,uCreatedBy))
395                printf(LANG_NBB_MODIFY);
396
397        if(uAllowDel(uOwner,uCreatedBy))
398                printf(LANG_NBB_DELETE);
399
400        if(uOwner)
401                printf(LANG_NBB_LIST);
402
403        printf(LANG_NBB_SKIPNEXT);
404        printf(LANG_NBB_SKIPLAST);
405        printf("&nbsp;&nbsp;&nbsp;\n");
406
407}//void ExttDatacenterNavBar(void)
408
409
410void tDatacenterNavList(void)
411{
412        MYSQL_RES *res;
413        MYSQL_ROW field;
414
415        ExtSelect("tDatacenter","tDatacenter.uDatacenter,tDatacenter.cLabel");
416
417        mysql_query(&gMysql,gcQuery);
418        if(mysql_errno(&gMysql))
419        {
420                printf("<p><u>tDatacenterNavList</u><br>\n");
421                printf("%s",mysql_error(&gMysql));
422                return;
423        }
424
425        res=mysql_store_result(&gMysql);
426        if(mysql_num_rows(res))
427        {       
428                printf("<p><u>tDatacenterNavList</u><br>\n");
429
430                while((field=mysql_fetch_row(res)))
431                        printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tDatacenter&uDatacenter=%s>"
432                                "%s</a><br>\n",field[0],field[1]);
433        }
434        mysql_free_result(res);
435
436}//void tDatacenterNavList(void)
437
438
439void tDatacenterHealth(void)
440{
441        MYSQL_RES *res;
442        MYSQL_ROW field;
443
444
445        printf("<p>Select uNode<br>");
446        tTablePullDownDatacenter("tNode;cuTargetNodePullDown","cLabel","cLabel",uTargetNode,1,
447                        "",0,uDatacenter);//0 does not use tProperty, uses uDatacenter
448
449        //1-. Disk space usage/soft limit ratio
450        //1a-. Create temp table
451        sprintf(gcQuery,"CREATE TEMPORARY TABLE tDiskUsage (uContainer INT UNSIGNED NOT NULL DEFAULT 0,"
452                        " luUsage INT UNSIGNED NOT NULL DEFAULT 0, luSoftlimit INT UNSIGNED NOT NULL DEFAULT 0,"
453                        " cLabel VARCHAR(32) NOT NULL DEFAULT '')");
454        mysql_query(&gMysql,gcQuery);
455        if(mysql_errno(&gMysql))
456        {
457                printf("<p><u>tDatacenterHealth</u><br>\n");
458                printf("a-. %s",mysql_error(&gMysql));
459                return;
460        }
461
462        //1b-. Populate with data per container
463        if(uTargetNode)
464                sprintf(gcQuery,"SELECT tProperty.uKey,tProperty.cValue,tContainer.cLabel FROM tProperty,tContainer"
465                        " WHERE tProperty.uKey=tContainer.uContainer AND tProperty.uType=3 AND"
466                        " tProperty.cName='1k-blocks.luUsage' AND tContainer.uDatacenter=%u"
467                        " AND tContainer.uNode=%u"
468                        " AND tContainer.uStatus=1",uDatacenter,uTargetNode);
469        else
470                sprintf(gcQuery,"SELECT tProperty.uKey,tProperty.cValue,tContainer.cLabel FROM tProperty,tContainer"
471                        " WHERE tProperty.uKey=tContainer.uContainer AND tProperty.uType=3 AND"
472                        " tProperty.cName='1k-blocks.luUsage' AND tContainer.uDatacenter=%u"
473                        " AND tContainer.uStatus=1",uDatacenter);
474        mysql_query(&gMysql,gcQuery);
475        if(mysql_errno(&gMysql))
476        {
477                printf("<p><u>tDatacenterHealth</u><br>\n");
478                printf("0-. %s",mysql_error(&gMysql));
479                return;
480        }
481        res=mysql_store_result(&gMysql);
482        while((field=mysql_fetch_row(res)))
483        {       
484                sprintf(gcQuery,"INSERT INTO tDiskUsage SET uContainer=%s,luUsage=%s,cLabel='%.32s'",
485                        field[0],field[1],field[2]);
486                mysql_query(&gMysql,gcQuery);
487                if(mysql_errno(&gMysql))
488                {
489                        printf("<p><u>tDatacenterHealth</u><br>\n");
490                        printf("1-. %s",mysql_error(&gMysql));
491                        return;
492                }
493        }
494        mysql_free_result(res);
495
496        if(uTargetNode)
497                sprintf(gcQuery,"SELECT tProperty.uKey,tProperty.cValue FROM tProperty,tContainer"
498                        " WHERE tProperty.uKey=tContainer.uContainer AND tProperty.uType=3 AND"
499                        " tProperty.cName='1k-blocks.luSoftLimit' AND tContainer.uDatacenter=%u"
500                        " AND tContainer.uNode=%u"
501                        " AND tContainer.uStatus=1",uDatacenter,uTargetNode);
502        else
503                sprintf(gcQuery,"SELECT tProperty.uKey,tProperty.cValue FROM tProperty,tContainer"
504                        " WHERE tProperty.uKey=tContainer.uContainer AND tProperty.uType=3 AND"
505                        " tProperty.cName='1k-blocks.luSoftLimit' AND tContainer.uDatacenter=%u"
506                        " AND tContainer.uStatus=1",uDatacenter);
507        mysql_query(&gMysql,gcQuery);
508        if(mysql_errno(&gMysql))
509        {
510                printf("<p><u>tDatacenterHealth</u><br>\n");
511                printf("2-. %s",mysql_error(&gMysql));
512                return;
513        }
514        res=mysql_store_result(&gMysql);
515        while((field=mysql_fetch_row(res)))
516        {       
517                sprintf(gcQuery,"UPDATE tDiskUsage SET luSoftlimit=%s WHERE uContainer=%s",field[1],field[0]);
518                mysql_query(&gMysql,gcQuery);
519                if(mysql_errno(&gMysql))
520                {
521                        printf("<p><u>tDatacenterHealth</u><br>\n");
522                        printf("3-. %s",mysql_error(&gMysql));
523                        return;
524                }
525        }
526        mysql_free_result(res);
527
528        //1d-. Report
529        unsigned luSoftlimit;
530        unsigned luUsage;
531        float fRatio;
532        char *cColor;
533               
534        sprintf(gcQuery,"SELECT luSoftlimit,luUsage,uContainer,cLabel FROM tDiskUsage"
535                        " WHERE ((luUsage/luSoftlimit)>0.5)"
536                        " ORDER BY (luUsage/luSoftlimit) DESC LIMIT 20");
537        mysql_query(&gMysql,gcQuery);
538        if(mysql_errno(&gMysql))
539        {
540                printf("4-. %s",mysql_error(&gMysql));
541                return;
542        }
543        res=mysql_store_result(&gMysql);
544        if(mysql_num_rows(res)>0)
545                printf("<p><u>Top 20 Containers by Usage Ratio (50%%+)</u><br>\n");
546        while((field=mysql_fetch_row(res)))
547        {
548                luSoftlimit=0;
549                luUsage=0;
550                sscanf(field[0],"%u",&luSoftlimit);
551                sscanf(field[1],"%u",&luUsage);
552                //Strange values hack
553                if(!luUsage)
554                        luUsage=1;
555                if(!luSoftlimit)
556                        luSoftlimit=luUsage;
557                fRatio= ((float) luUsage/ (float) luSoftlimit) * 100.00 ;
558                cColor=cRatioColor(&fRatio);
559
560                printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>"
561                                "<font color=%s>%2.2f%% %s</font></a><br>\n",field[2],cColor,fRatio,field[3]);
562        }
563        mysql_free_result(res);
564
565
566        //2-. None zero historic fail counters
567        if(uTargetNode)
568                sprintf(gcQuery,"SELECT cValue,uKey,cLabel,cName FROM tProperty,tContainer WHERE"
569                        " tProperty.uKey=tContainer.uContainer AND"
570                        " tContainer.uDatacenter=%u AND"
571                        " tContainer.uNode=%u AND"
572                        " cValue!='0' AND uType=3 AND cName LIKE '%%.luFailcnt'"
573                        " ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uDatacenter,uTargetNode);
574        else
575                sprintf(gcQuery,"SELECT cValue,uKey,cLabel,cName FROM tProperty,tContainer WHERE"
576                        " tProperty.uKey=tContainer.uContainer AND"
577                        " tContainer.uDatacenter=%u AND"
578                        " cValue!='0' AND uType=3 AND cName LIKE '%%.luFailcnt'"
579                        " ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uDatacenter);
580        mysql_query(&gMysql,gcQuery);
581        if(mysql_errno(&gMysql))
582        {
583                printf("<p><u>tDatacenterHealth</u><br>\n");
584                printf("5-. %s",mysql_error(&gMysql));
585                return;
586        }
587
588        res=mysql_store_result(&gMysql);
589        if(mysql_num_rows(res))
590        {       
591                printf("<p><u>Top 10 Containers by X.luFailcnt</u><br>\n");
592
593                while((field=mysql_fetch_row(res)))
594                        printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>"
595                                "%s %s=%s</a><br>\n",field[1],field[2],field[3],field[0]);
596        }
597        mysql_free_result(res);
598
599        //3a-. Todays top in
600        if(uTargetNode)
601                sprintf(gcQuery,"SELECT FORMAT(SUM(cValue/1000),2),uKey,cHostname,TIME(FROM_UNIXTIME(tProperty.uModDate)) FROM"
602                        " tProperty,tContainer WHERE"
603                        " tProperty.uKey=tContainer.uContainer AND cValue!='0' AND uType=3 AND"
604                        " tContainer.uStatus=%u AND"
605                        " tContainer.uDatacenter=%u AND"
606                        " tContainer.uNode=%u AND"
607                        " cName='Venet0.luMaxDailyInDelta'"
608                        " GROUP BY uKey ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uACTIVE,uDatacenter,uTargetNode);
609        else
610                sprintf(gcQuery,"SELECT FORMAT(SUM(cValue/1000),2),uKey,cHostname,TIME(FROM_UNIXTIME(tProperty.uModDate)) FROM"
611                        " tProperty,tContainer WHERE"
612                        " tProperty.uKey=tContainer.uContainer AND cValue!='0' AND uType=3 AND"
613                        " tContainer.uStatus=%u AND"
614                        " tContainer.uDatacenter=%u AND"
615                        " cName='Venet0.luMaxDailyInDelta'"
616                        " GROUP BY uKey ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uACTIVE,uDatacenter);
617        mysql_query(&gMysql,gcQuery);
618        if(mysql_errno(&gMysql))
619        {
620                printf("<p><u>tDatacenterHealth</u><br>\n");
621                printf("5-. %s",mysql_error(&gMysql));
622                return;
623        }
624        res=mysql_store_result(&gMysql);
625        if(mysql_num_rows(res))
626        {       
627                printf("<p><u>Today's peak in talkers</u><br>\n");
628
629                while((field=mysql_fetch_row(res)))
630                        printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>"
631                                "%s/%s %sKB/s</a><br>\n",field[1],field[2],field[3],field[0]);
632        }
633        mysql_free_result(res);
634
635        //3b-. Todays top out
636        if(uTargetNode)
637                sprintf(gcQuery,"SELECT FORMAT(SUM(cValue/1000),2),uKey,cHostname,TIME(FROM_UNIXTIME(tProperty.uModDate)) FROM"
638                        " tProperty,tContainer WHERE"
639                        " tProperty.uKey=tContainer.uContainer AND cValue!='0' AND uType=3 AND"
640                        " tContainer.uStatus=%u AND"
641                        " tContainer.uDatacenter=%u AND"
642                        " tContainer.uNode=%u AND"
643                        " cName='Venet0.luMaxDailyOutDelta'"
644                        " GROUP BY uKey ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uACTIVE,uDatacenter,uTargetNode);
645        else
646                sprintf(gcQuery,"SELECT FORMAT(SUM(cValue/1000),2),uKey,cHostname,TIME(FROM_UNIXTIME(tProperty.uModDate)) FROM"
647                        " tProperty,tContainer WHERE"
648                        " tProperty.uKey=tContainer.uContainer AND cValue!='0' AND uType=3 AND"
649                        " tContainer.uStatus=%u AND"
650                        " tContainer.uDatacenter=%u AND"
651                        " cName='Venet0.luMaxDailyOutDelta'"
652                        " GROUP BY uKey ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uACTIVE,uDatacenter);
653        mysql_query(&gMysql,gcQuery);
654        if(mysql_errno(&gMysql))
655        {
656                printf("<p><u>tDatacenterHealth</u><br>\n");
657                printf("5-. %s",mysql_error(&gMysql));
658                return;
659        }
660        res=mysql_store_result(&gMysql);
661        if(mysql_num_rows(res))
662        {       
663                printf("<p><u>Today's peak out talkers</u><br>\n");
664
665                while((field=mysql_fetch_row(res)))
666                        printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>"
667                                "%s/%s %sKB/s</a><br>\n",field[1],field[2],field[3],field[0]);
668        }
669        mysql_free_result(res);
670
671        //4-. Last 5 min top talkers
672        if(uTargetNode)
673                sprintf(gcQuery,"SELECT FORMAT(SUM(cValue/2000),2),uKey,cHostname FROM"
674                        " tProperty,tContainer WHERE"
675                        " tProperty.uKey=tContainer.uContainer AND cValue!='0' AND uType=3 AND"
676                        " tContainer.uStatus=%u AND"
677                        " tContainer.uDatacenter=%u AND"
678                        " tContainer.uNode=%u AND"
679                        " (cName='Venet0.luInDelta' OR cName='Venet0.luOutDelta')"
680                        " GROUP BY uKey ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uACTIVE,uDatacenter,uTargetNode);
681        else
682                sprintf(gcQuery,"SELECT FORMAT(SUM(cValue/2000),2),uKey,cHostname FROM"
683                        " tProperty,tContainer WHERE"
684                        " tProperty.uKey=tContainer.uContainer AND cValue!='0' AND uType=3 AND"
685                        " tContainer.uStatus=%u AND"
686                        " tContainer.uDatacenter=%u AND"
687                        " (cName='Venet0.luInDelta' OR cName='Venet0.luOutDelta')"
688                        " GROUP BY uKey ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uACTIVE,uDatacenter);
689        mysql_query(&gMysql,gcQuery);
690        if(mysql_errno(&gMysql))
691        {
692                printf("<p><u>tDatacenterHealth</u><br>\n");
693                printf("5-. %s",mysql_error(&gMysql));
694                return;
695        }
696        res=mysql_store_result(&gMysql);
697        if(mysql_num_rows(res))
698        {       
699                printf("<p><u>Last 5min top talkers</u><br>\n");
700
701                while((field=mysql_fetch_row(res)))
702                        printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>"
703                                "%s %sKB/s</a><br>\n",field[1],field[2],field[0]);
704        }
705        mysql_free_result(res);
706
707        //4b-. Last 5 min top diff talkers
708        if(uTargetNode)
709                sprintf(gcQuery,"SELECT ABS(CONVERT(t2.cValue,SIGNED)-CONVERT(t1.cValue,SIGNED)),t1.uKey,t1.uKey FROM"
710                        " tProperty AS t1, tProperty AS t2 WHERE"
711                        " t1.uKey IN (SELECT uContainer from tContainer where uStatus=%u AND uDatacenter=%u AND uNode=%u) AND"
712                        " t1.uKey=t2.uKey AND t1.uType=3 AND t1.cName='Venet0.luInDelta' AND"
713                        " t2.uKey=t2.uKey AND t2.uType=3 AND t2.cName='Venet0.luOutDelta'"
714                        " ORDER BY ABS(CONVERT(t2.cValue,SIGNED)-CONVERT(t1.cValue,SIGNED)) DESC LIMIT 10",uACTIVE,uDatacenter,uTargetNode);
715        else
716                sprintf(gcQuery,"SELECT ABS(CONVERT(t2.cValue,SIGNED)-CONVERT(t1.cValue,SIGNED)),t1.uKey,t1.uKey FROM"
717                        " tProperty AS t1, tProperty AS t2 WHERE"
718                        " t1.uKey IN (SELECT uContainer from tContainer where uStatus=%u AND uDatacenter=%u) AND"
719                        " t1.uKey=t2.uKey AND t1.uType=3 AND t1.cName='Venet0.luInDelta' AND"
720                        " t2.uKey=t2.uKey AND t2.uType=3 AND t2.cName='Venet0.luOutDelta'"
721                        " ORDER BY ABS(CONVERT(t2.cValue,SIGNED)-CONVERT(t1.cValue,SIGNED)) DESC LIMIT 10",uACTIVE,uDatacenter);
722        mysql_query(&gMysql,gcQuery);
723        if(mysql_errno(&gMysql))
724        {
725                printf("<p><u>tDatacenterHealth</u><br>\n");
726                printf("5-. %s",mysql_error(&gMysql));
727                return;
728        }
729        res=mysql_store_result(&gMysql);
730        if(mysql_num_rows(res))
731        {       
732                printf("<p><u>Last 5min top diff</u><br>\n");
733
734                while((field=mysql_fetch_row(res)))
735                        printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>"
736                                "%s %sB/s</a><br>\n",field[1],field[2],field[0]);
737        }
738        mysql_free_result(res);
739
740        //4-. Top talkers
741        if(uTargetNode)
742                sprintf(gcQuery,"SELECT FORMAT(SUM(cValue/1000000000),2),uKey,cHostname FROM"
743                        " tProperty,tContainer WHERE"
744                        " tContainer.uStatus=%u AND"
745                        " tContainer.uDatacenter=%u AND"
746                        " tContainer.uNode=%u AND"
747                        " tProperty.uKey=tContainer.uContainer AND cValue!='0' AND uType=3 AND"
748                        " (cName='Venet0.luIn' OR cName='Venet0.luOut')"
749                        " GROUP BY uKey ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uACTIVE,uDatacenter,uTargetNode);
750        else
751                sprintf(gcQuery,"SELECT FORMAT(SUM(cValue/1000000000),2),uKey,cHostname FROM"
752                        " tProperty,tContainer WHERE"
753                        " tContainer.uStatus=%u AND"
754                        " tContainer.uDatacenter=%u AND"
755                        " tProperty.uKey=tContainer.uContainer AND cValue!='0' AND uType=3 AND"
756                        " (cName='Venet0.luIn' OR cName='Venet0.luOut')"
757                        " GROUP BY uKey ORDER BY CONVERT(cValue,UNSIGNED) DESC LIMIT 10",uACTIVE,uDatacenter);
758        mysql_query(&gMysql,gcQuery);
759        if(mysql_errno(&gMysql))
760        {
761                printf("<p><u>tDatacenterHealth</u><br>\n");
762                printf("5-. %s",mysql_error(&gMysql));
763                return;
764        }
765
766        res=mysql_store_result(&gMysql);
767        if(mysql_num_rows(res))
768        {       
769                printf("<p><u>Historic top talkers</u><br>\n");
770
771                while((field=mysql_fetch_row(res)))
772                        printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>"
773                                "%s %sGB</a><br>\n",field[1],field[2],field[0]);
774        }
775        mysql_free_result(res);
776
777}//void tDatacenterHealth(void)
778
779
Note: See TracBrowser for help on using the browser.