Implementation of TIMEPERIOD_{THIS,LAST}QUARTER

Ken Brownfield nagios-devel at mrlventures.com
Wed May 4 05:16:39 CEST 2005


I noticed that these time periods aren't implemented in the Nagios  
CGIs, so I implemented them a few months ago for the availability  
reports.  Presumably these can also be applied to histogram, summary,  
and trends.

But I wanted to pass this by this list, since I'm seeing some  
unpredictable behavior.  I'm concerned that this code is either  
touching ugly internals or just plain wrongly implemented.  It works,  
but the lines with the "Why" comments are concerning.  My  
modification of t->tm_hour had to be -1 in v1.2, and now has to be 1  
in v2.0b3, neither value being expected.

These time periods might be useful for folk who work at shops that  
track quarterly availability.

Thanks,
-- 
Ken.


--- avail.c    2005/05/03 23:26:44    1.1
+++ avail.c    2005/05/04 00:14:22
@@ -567,6 +567,8 @@
              printf("<option value=thismonth %s>This Month\n", 
(timeperiod_type==TIMEPERIOD_THISMONTH)?"SELECTED":"");
              printf("<option value=last31days %s>Last 31 Days\n", 
(timeperiod_type==TIMEPERIOD_LAST31DAYS)?"SELECTED":"");
              printf("<option value=lastmonth %s>Last Month\n", 
(timeperiod_type==TIMEPERIOD_LASTMONTH)?"SELECTED":"");
+            printf("<option value=thisquarter %s>This Quarter\n", 
(timeperiod_type==TIMEPERIOD_THISQUARTER)?"SELECTED":"");
+            printf("<option value=lastquarter %s>Last Quarter\n", 
(timeperiod_type==TIMEPERIOD_LASTQUARTER)?"SELECTED":"");
              printf("<option value=thisyear %s>This Year\n", 
(timeperiod_type==TIMEPERIOD_THISYEAR)?"SELECTED":"");
              printf("<option value=lastyear %s>Last Year\n", 
(timeperiod_type==TIMEPERIOD_LASTYEAR)?"SELECTED":"");
              printf("</select>\n");
@@ -660,6 +662,8 @@
          printf("<option value=thismonth>This Month\n");
          printf("<option value=last31days>Last 31 Days\n");
          printf("<option value=lastmonth>Last Month\n");
+        printf("<option value=thisquarter>This Quarter\n");
+        printf("<option value=lastquarter>Last Quarter\n");
          printf("<option value=thisyear>This Year\n");
          printf("<option value=lastyear>Last Year\n");
          printf("<option value=custom>* CUSTOM REPORT PERIOD *\n");
@@ -3147,10 +3151,30 @@
          t1=mktime(t);
          break;
      case TIMEPERIOD_THISQUARTER:
-        /* not implemented */
+        t->tm_mon = t->tm_mon - ( t->tm_mon % 3 );
+        t->tm_mday = 1 ;
+        t->tm_hour = 1 ;    /* Why not 0 ??? */
+        t1=mktime(t);
+        t2=current_time;
          break;
      case TIMEPERIOD_LASTQUARTER:
-        /* not implemented */
+        if ( t->tm_mon < 3 ) {
+            t->tm_mon = 0 ;
+            t->tm_mday = 1 ;
+            t2 = mktime(t) - 1 ;
+            t->tm_year-- ;
+            t->tm_mon = 9 ;
+            t->tm_hour = 0 ;    /* This makes sense... */
+            t1 = mktime(t);
+        }
+        else {
+            t->tm_mon = t->tm_mon - ( t->tm_mon % 3 );
+            t->tm_mday = 1 ;
+            t->tm_hour = 1 ;    /* Why not 0 ??? */
+            t2 = mktime(t) - 1 ;
+            t->tm_mon -= 3 ;
+            t1 = mktime(t);
+        }
          break;
      case TIMEPERIOD_THISYEAR:
          t->tm_mon=0;



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20




More information about the Developers mailing list