Exemple #1
0
/******************************************************************************
 *                                                                            *
 * Function: housekeeping_history                                             *
 *                                                                            *
 * Purpose: remove outdated information from history and trends               *
 *                                                                            *
 * Parameters: now - current timestamp                                        *
 *                                                                            *
 * Return value: SUCCEED - information removed successfully                   *
 *               FAIL - otherwise                                             *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static int	housekeeping_history(int now)
{
        int	records = 0;

        zabbix_log(LOG_LEVEL_DEBUG, "In housekeeping_history()");

	records += delete_history("proxy_history", "history_lastid", now);
	records += delete_history("proxy_dhistory", "dhistory_lastid", now);
	records += delete_history("proxy_autoreg_host", "autoreg_host_lastid", now);

        return records;
}
/******************************************************************************
 *                                                                            *
 * Function: housekeeping_history_and_trends                                  *
 *                                                                            *
 * Purpose: remove outdated information from history and trends               *
 *                                                                            *
 * Parameters: now - current timestamp                                        *
 *                                                                            *
 * Return value: SUCCEED - information removed successfully                   *
 *               FAIL - otherwise                                             *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static int	housekeeping_history_and_trends(int now)
{
	DB_ITEM         item;
	DB_RESULT       result;
	DB_ROW          row;
	int             deleted = 0;

	zabbix_log(LOG_LEVEL_DEBUG, "In housekeeping_history_and_trends() now:%d", now);

	result = DBselect("select itemid,history,trends from items");

	while (NULL != (row = DBfetch(result)))
	{
		ZBX_STR2UINT64(item.itemid, row[0]);
		item.history = atoi(row[1]);
		item.trends = atoi(row[2]);

		deleted += delete_history("history", item.itemid, item.history, now);
		deleted += delete_history("history_uint", item.itemid, item.history, now);
		deleted += delete_history("history_str", item.itemid, item.history, now);
		deleted += delete_history("history_text", item.itemid, item.history, now);
		deleted += delete_history("history_log", item.itemid, item.history, now);
		deleted += delete_history("trends", item.itemid, item.trends, now);
		deleted += delete_history("trends_uint", item.itemid, item.trends, now);
	}
	DBfree_result(result);

	return deleted;
}
void exit_app(void)
{
	(void)font_exit();
	(void)delete_history();
	(void)ftp_off();
	(void)InputExit();
	UnloadModules();
	exit(1);
}
int init_core(void)
{
	(void)delete_history();
	(void)ftp_on();
	//(void)CheckFWVersion();
	//if(!fan_init()) {
		// unsupported fw error...
	//}

	textures		= (c_tex**)malloc(sizeof(c_tex) * 10);
	memset(textures, 0, sizeof(c_tex) * 10);

	textures[0]		= new c_tex(0, (char*)"/dev_hdd0/game/SISO00123/USRDIR/gfx/BG.PNG");

	InitMainMenu();
	return 1;
}
/******************************************************************************
 *                                                                            *
 * Function: housekeeping_history_and_trends                                  *
 *                                                                            *
 * Purpose: remove outdated information from history and trends               *
 *                                                                            *
 * Parameters: now - current timestamp                                        *
 *                                                                            *
 * Return value: number of rows deleted                                       *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static int	housekeeping_history_and_trends(int now)
{
	const char	*__function_name = "housekeeping_history_and_trends";
	zbx_uint64_t	itemid;
	DB_RESULT       result;
	DB_ROW          row;
	int             history, trends, deleted = 0;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s() now:%d", __function_name, now);

	result = DBselect(
			"select i.itemid,i.history,i.trends from items i,hosts h"
			" where i.hostid=h.hostid"
				" and h.status in (%d,%d)",
			HOST_STATUS_MONITORED, HOST_STATUS_NOT_MONITORED);

	while (NULL != (row = DBfetch(result)))
	{
		ZBX_STR2UINT64(itemid, row[0]);
		history = atoi(row[1]);
		trends = atoi(row[2]);

		deleted += delete_history("history", itemid, history, now);
		deleted += delete_history("history_uint", itemid, history, now);
		deleted += delete_history("history_str", itemid, history, now);
		deleted += delete_history("history_text", itemid, history, now);
		deleted += delete_history("history_log", itemid, history, now);
		deleted += delete_history("trends", itemid, trends, now);
		deleted += delete_history("trends_uint", itemid, trends, now);
	}
	DBfree_result(result);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%d", __function_name, deleted);

	return deleted;
}
Exemple #6
0
void chat_interface(int new_fd)
{
    clear();
    refresh();
    
    int flag = 3;

    int ch;

    WINDOW *new_window1, *new_window2, *new_window5;

    setlocale(LC_ALL, "");
    //initscr();

    //keypad(ch_window4, 1);

    new_window1 = newwin(3, 91,0,22);
    ch_window2 = newwin(13, 68,4,23);
    new_window5 = newwin(15, 70,3,22);
    ch_window3 = newwin(6, 70,18,22);
    ch_window4 = newwin(21, 21,3,92);
    ch_window5 = newwin(6, 20,0,2);
    ch_window1 = newwin(18, 20,6,2);

    box(new_window1, 0, 0);
    box(ch_window4, 0, 0);
    box(ch_window5, 0, 0);
    box(new_window5, 0, 0);
    box(ch_window1, 0, 0);
    box(ch_window2, ' ', ' ');
    box(ch_window3, 0, 0);

    mvwaddstr(ch_window1, 1, 5, "ONLINE-USER");
    mvwaddstr(ch_window1, 2, 5, "===========");

    mvwaddstr(ch_window5, 2, 7, msg1.name);
    mvwaddstr(ch_window5, 3, 6, msg1.id);
    
    mvwaddstr(ch_window4, 1, 6, "FUNCTION");
    mvwaddstr(ch_window4, 2, 5, "===========");
    mvwaddstr(ch_window4, 3, 5, "私聊");
    mvwaddstr(ch_window4, 4, 5, "群聊");
    mvwaddstr(ch_window4, 5, 5, "发送表情");
    mvwaddstr(ch_window4, 6, 5, "查看聊天记录");
    mvwaddstr(ch_window4, 7, 5, "删除聊天记录");
    mvwaddstr(ch_window4, 8, 5, "发送文件");
    mvwaddstr(ch_window4, 9, 5, "修改昵称");
    mvwaddstr(ch_window4, 10, 5, "修改密码");
    mvwaddstr(ch_window4, 11, 5, "切换用户");

    wrefresh(new_window1);
    wrefresh(ch_window3);
    wrefresh(ch_window5);
    wrefresh(new_window5);
    wrefresh(ch_window1);
    wrefresh(ch_window2);
    wrefresh(ch_window4);
 
    mvwaddstr(ch_window4, flag, 3, "=>");
    wrefresh(ch_window4);

    keypad(ch_window4,true);

    cbreak();

    while(1)
    {
        if(filesend == FILE_SEND)
	{
	    file_receive(new_fd);

	    filesend = 0;
	}

        curs_set(0);
        
        /*mvwaddstr(ch_window4, flag, 3, "  ");
	
	flag = 3;

        mvwaddstr(ch_window4, flag, 3, "=>");
	wrefresh(ch_window4);*/

        noecho();
        while((ch = wgetch(ch_window4)) != '\n')
	{
	    if(ch == KEY_UP)
	    {
		mvwaddstr(ch_window4, flag, 3, "  ");

	        if(flag == 3)
		{
		    flag = 11;
		}
		else
		{
		    flag--;
		}

		mvwaddstr(ch_window4, flag, 3, "=>");
	    }
	    if(ch == KEY_DOWN)
	    {
		mvwaddstr(ch_window4, flag, 3, "  ");
                 
	        if(flag == 11)
		{
		    flag = 3;
		}
		else
		{
		    flag++;
		}

		mvwaddstr(ch_window4, flag, 3, "=>");
	        
	    }

	    wrefresh(ch_window4);
	}

	switch(flag)
	{
	    case 3:
	    {
	        private_chat(new_fd);
                break;
	    }
	    case 4:
	    {
	        group_chat(new_fd);
	        break;
	    }
	    case 5:
	    {   
	        send_face(new_fd);
	        break;
	    }
	    case 6:
	    {
	        check_history(new_fd);
	        break;
	    }
	    case 7:
	    {
	        delete_history(new_fd);
	        break;
	    }
	    case 8:
	    {
	        file_send(new_fd);
	        break;
	    }
	    case 9:
	    {
	        change_name(new_fd);
	        break;
	    }
	    case 10:
	    {
 
	        change_password(new_fd);

    box(new_window1, 0, 0);
    box(ch_window4, 0, 0);
    box(ch_window5, 0, 0);
    box(new_window5, 0, 0);
    box(ch_window1, 0, 0);
    box(ch_window2, ' ', ' ');
    box(ch_window3, 0, 0);

    mvwaddstr(ch_window1, 1, 5, "ONLINE-USER");
    mvwaddstr(ch_window1, 2, 5, "===========");

    mvwaddstr(ch_window5, 2, 7, msg1.name);
    mvwaddstr(ch_window5, 3, 6, msg1.id);
    
    mvwaddstr(ch_window4, 1, 6, "FUNCTION");
    mvwaddstr(ch_window4, 2, 5, "===========");
    mvwaddstr(ch_window4, 3, 5, "私聊");
    mvwaddstr(ch_window4, 4, 5, "群聊");
    mvwaddstr(ch_window4, 5, 5, "发送表情");
    mvwaddstr(ch_window4, 6, 5, "查看聊天记录");
    mvwaddstr(ch_window4, 7, 5, "删除聊天记录");
    mvwaddstr(ch_window4, 8, 5, "发送文件");
    mvwaddstr(ch_window4, 9, 5, "修改昵称");
    mvwaddstr(ch_window4, 10, 5, "修改密码");
    mvwaddstr(ch_window4, 11, 5, "切换用户");

    wrefresh(new_window1);
    wrefresh(ch_window3);
    wrefresh(ch_window5);
    wrefresh(new_window5);
    wrefresh(ch_window1);
    wrefresh(ch_window2);
    wrefresh(ch_window4);
 
    mvwaddstr(ch_window4, flag, 3, "=>");
    wrefresh(ch_window4);


                     break;

	    }
	    case 11:
	    {
                clear();
                refresh();
                new_window2 = newwin(13, 50, 5, 30);
                box(new_window2, 0, 0);
                mvwaddstr(new_window2, 3, 22, "GOODBYE");
                mvwaddstr(new_window2, 5, 22, msg1.name);
		wrefresh(new_window2);

		msg1.action = QUIT;
		write(new_fd, &msg1, sizeof(Node));

	        goto EXIT_CHATINTERFACE;
	        break;
	    }
	}
    }

    EXIT_CHATINTERFACE:

    curs_set(1);
    wgetch(new_window1);

}
/*
 * PSEUDO CODE:
 *
 * EXTRACT INFO FROM XML NODE
 * RETRIEVE PROBE DEFINITION RECORD FROM DATABASE
 * RETRIEVE PRECEDING RAW RECORD FROM DATABASE
 * STORE RAW RESULTS
 * IF THIS IS THE FIRST RESULT EVER FOR THIS PROBE
 *   CREATE PR_STATUS RECORD
 * ELSE
 *   IF WE HAVEN'T PROCESSED THIS RECORD BEFORE
 *     IF COLOR DIFFERS FROM PRECEDING RAW RECORD
 *       CREATE PR_HIST
 *       RETRIEVE FOLLOWING RAW RECORD
 *       IF FOUND AND COLOR OF FOLLOWING IS THE SAME AS CURRENT
 *         DELETE POSSIBLE HISTORY RECORDS FOR FOLLOWING RECORD
 *       ENDIF
 *       IF THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED
 *         WRITE NEW RECENT TIME INTO PROBE DEFINITION RECORD
 *         UPDATE PR_STATUS
 *         UPDATE SERVER COLOR
 *       ENDIF
 *     ELSE
 *       IF THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED
 *         WRITE NEW RECENT TIME INTO PROBE DEFINITION RECORD
 *       ENDIF
 *     ENDIF
 *     IF CURRENT RAW RECORD IS THE MOST RECENT
 *       FOR EACH PERIOD
 *         IF WE ENTERED A NEW SLOT
 *           SUMMARIZE PREVIOUS SLOT
 *         ENDIF
 *       ENDFOR
 *     ELSE
 *       FOR EACH PERIOD
 *         IF THE LAST RECORD FOR THIS SLOT HAS BEEN SEEN
 *           RE-SUMMARIZE CURRENT SLOT
 *         ENDIF
 *       ENDFOR
 *     ENDIF
 *   ENDIF
 * ENDIF
 *
 * returns:
 *  1 in case of success
 *  0 in case of database failure where trying again later might help
 * -1 in case of malformed input, never try again
 * -2 in case of a fatal error, just skip this batch
 */
int process(trx *t)
{
  int must_update_def=0;
  struct probe_result *prv=NULL;
  int err = 1; /* default ok */

  if (!realm_exists(t->res->realm)) {
    return -1;
  }

  if (t->res->realm && t->res->realm[0]) {
    t->probe->db = open_realm(t->res->realm);
  } else {
    if (t->probe->find_realm) {
      t->probe->find_realm(t);
    } else {
      t->probe->db = open_realm(NULL);
    }
  }
  if (!t->probe->db) return -2;

  if (t->probe->resultcount % 400 == 0) {
    update_last_seen(t->probe);
  }

  if (debug > 3) fprintf(stderr, "accept_result\n");
  if (t->probe->accept_result) {
    t->probe->accept_result(t); // do some final calculations on the result
  }

  if (debug > 3) fprintf(stderr, "get_def\n");
  if (t->probe->get_def) {
    if (debug > 3) fprintf(stderr, "RETRIEVE PROBE DEFINITION RECORD FROM DATABASE\n");
    t->def = t->probe->get_def(t, trust(t->res->name)); // RETRIEVE PROBE DEFINITION RECORD FROM DATABASE
  } else {
    t->def = get_def(t, trust(t->res->name));
  }
  if (!t->def) {  // Oops, def record not found. Skip this probe
    if (debug > 3) fprintf(stderr, "def NOT found\n");
    err = -1; /* malformed input FIXME should make distinction between db errors and def not found */
    goto exit_with_res;
  }
  if (t->probe->adjust_result) {
    t->probe->adjust_result(t);
  }

  if (debug > 3) fprintf(stderr, "STORE RAW RESULTS\n");
  if (t->probe->store_results) {
    int ret = t->probe->store_results(t); // STORE RAW RESULTS
    if (!ret) { /* error return? */
      if (debug > 3) fprintf(stderr, "error in store_results\n");
      err = -2; /* database fatal error - try again later */
      goto exit_with_res;
    }
  } else {
    t->seen_before = FALSE;
  }

  if (t->res->stattime > t->def->newest) { // IF CURRENT RAW RECORD IS THE MOST RECENT 
    if (debug > 3) fprintf(stderr, "CURRENT RAW RECORD IS THE MOST RECENT\n");
    prv = g_malloc0(sizeof(struct probe_result));
    prv->color = t->def->color;  // USE PREVIOUS COLOR FROM DEF RECORD
    prv->stattime = t->def->newest;
  } else {
    if (debug > 3) fprintf(stderr, "RETRIEVE PRECEDING RAW RECORD FROM DATABASE\n");
    prv = get_previous_record(t); // RETRIEVE PRECEDING RAW RECORD FROM DATABASE
  }

  set_result_prev_color(t, prv); // indicate previous color in result set

  if (t->def->email[0]) { // and if email address given, add simple notification record
    xmlNodePtr notify;

    notify = xmlNewChild(t->cur, NULL, "notify", NULL);
    xmlSetProp(notify, "proto", "smtp");
    xmlSetProp(notify, "target", t->def->email);
  }

  if (t->def->newest == 0) { // IF THIS IS THE FIRST RESULT EVER FOR THIS PROBE
    if (debug > 3) fprintf(stderr, "THIS IS THE FIRST RESULT EVER FOR THIS PROBE\n");
    insert_pr_status(t);
    must_update_def = TRUE;
    goto finish;
  }
  if (t->seen_before) {
    goto finish;
  }
  
  // Extra debugging, be sure what colors are processed here
  if ( debug > 3 ) fprintf(stderr, "PREVIOUS COLOR %d - NEW COLOR %d\n", prv->color, t->res->color);

  // IF COLOR DIFFERS FROM PRECEDING RAW RECORD
  if (t->res->color != prv->color) {
    struct probe_result *nxt;

    if (t->probe->fuse) {
      if (t->res->color > prv->color || prv->color == STAT_PURPLE) {
        if (debug > 3) fprintf(stderr, "FUSE WITH HIGHER COLOR - CREATE PR_HIST\n");
        create_pr_hist(t, prv); // CREATE PR_HIST
      }
    } else {
      if (debug > 3) fprintf(stderr, "COLOR DIFFERS FROM PRECEDING RAW RECORD - CREATE PR_HIST\n");
      create_pr_hist(t, prv); // CREATE PR_HIST
    }
    if (t->res->stattime > t->def->newest) { // IF THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED
      dbi_result result;

      if (debug > 3) fprintf(stderr, "THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED - UPDATE PR_STATUS\n");
      result = update_pr_status(t, prv);    // UPDATE PR_STATUS
      if (dbi_result_get_numrows_affected(result) == 0) { // nothing was actually updated, need to insert new
        insert_pr_status(t); 
      }
      dbi_result_free(result);
      if (debug > 3) fprintf(stderr, "UPDATE SERVER COLOR\n");
      update_server_color(t, prv); // UPDATE SERVER COLOR
      must_update_def = TRUE;
    } else {
      if (debug > 3) fprintf(stderr, "RETRIEVE FOLLOWING RAW RECORD\n");
      nxt = get_following_record(t); // RETRIEVE FOLLOWING RAW RECORD
      if (nxt && nxt->color) { // IF FOUND
        if (debug > 3) fprintf(stderr, "FOLLOWING RECORD IS FOUND\n");
        if (nxt->color == t->res->color) {  // IF COLOR OF FOLLOWING IS THE SAME AS CURRENT
          if (debug > 3) fprintf(stderr, "SAME COLOR: DELETE POSSIBLE HISTORY RECORDS\n");
          delete_history(t, nxt); // DELETE POSSIBLE HISTORY RECORDS FOR FOLLOWING RECORD
        }
        g_free(nxt);
      }
    }
  } else {
    if (debug > 3) fprintf(stderr, "COLOR SAME AS PRECEDING RAW RECORD\n");
    if (t->res->stattime > t->def->newest) { // IF THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED
      dbi_result result;

      if (debug > 3) fprintf(stderr, "THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED - UPDATE PR_STATUS\n");
      result = update_pr_status(t, prv);  // UPDATE PR_STATUS (not for the color, but for the expiry time)
      if (dbi_result_get_numrows_affected(result) == 0) { // nothing was actually updated, need to insert new
        insert_pr_status(t); 
      }
      dbi_result_free(result);
      must_update_def = TRUE;
    }
  }

  if (t->def->email[0] || t->def->sms[0]) { // if we have an address
    // RETRIEVE LAST HIST ENTRY FOR THIS PROBE
    get_previous_pr_hist(t);

    // notify if needed
    if (strcmp(t->res->notified, "yes")) { // not already notified
      if (notify(t)) {
        set_pr_hist_notified(t);
      }
    }
  }

  if (t->probe->summarize && t->res->color != STAT_PURPLE) { 
    if (t->res->stattime > t->def->newest) { // IF CURRENT RAW RECORD IS THE MOST RECENT
      guint cur_slot, prev_slot;
      gulong slotlow, slothigh;
      gulong dummy_low, dummy_high;
      gint i;

      if (debug > 3) fprintf(stderr, "SUMMARIZING. CURRENT RAW RECORD IS THE MOST RECENT\n");
      for (i=0; summ_info[i].period != -1; i++) { // FOR EACH PERIOD
        prev_slot = uw_slot(summ_info[i].period, prv->stattime, &slotlow, &slothigh);
        cur_slot = uw_slot(summ_info[i].period, t->res->stattime, &dummy_low, &dummy_high);
        if (cur_slot != prev_slot) { // IF WE ENTERED A NEW SLOT, SUMMARIZE PREVIOUS SLOT
          if (debug > 3)  fprintf(stderr, "cur(%u for %u) != prv(%u for %u), summarizing %s from %lu to %lu",
                                          cur_slot, t->res->stattime, prev_slot, prv->stattime,
                                          summ_info[i].from, slotlow, slothigh);
          t->probe->summarize(t, summ_info[i].from, summ_info[i].to, 
                           cur_slot, slotlow, slothigh, 0);
        }
      }
    } else {
      guint cur_slot;
      gulong slotlow, slothigh;
      gulong not_later_then = UINT_MAX;
      gint i;

      if (debug > 3) {
        fprintf(stderr, "SUMMARIZING. CURRENT RAW RECORD IS AN OLD ONE\n");
        LOG(LOG_DEBUG, "stattime = %u, newest = %u for %s %u", t->res->stattime, t->def->newest,
          t->res->name, t->def->probeid);
      }
      for (i=0; summ_info[i].period != -1; i++) { // FOR EACH PERIOD
        cur_slot = uw_slot(summ_info[i].period, t->res->stattime, &slotlow, &slothigh);
        if (slothigh > not_later_then) continue; // we already know there are none later then this
        // IF THIS SLOT IS COMPLETE
        if (slot_is_complete(t, i, slotlow, slothigh)) {
          // RE-SUMMARIZE CURRENT SLOT
          if (debug > 3) fprintf(stderr, "SLOT IS COMPLETE - RE-SUMMARIZE CURRENT SLOT\n");
          t->probe->summarize(t, summ_info[i].from, summ_info[i].to, 
                           cur_slot, slotlow, slothigh, 0);
        } else {
          not_later_then = slothigh;
        }
      }
    }
  }

finish:
  if (must_update_def) {
    t->def->newest = t->res->stattime;
    t->def->color = t->res->color;
  }
  g_free(prv);

exit_with_res:
  if (t->probe->end_result) {
    t->probe->end_result(t);
  }

  // free the result block
  if (t->res) {
    if (t->probe->free_res) {
      t->probe->free_res(t->res); // the probe specific part...
    }
    free_res(t->res); // .. and the generic part
  }

  // note we don't free the *t->def here, because that structure is owned by the hashtable
  // except if the module does not use caching, we try to free it ourselves
  if (!t->probe->needs_cache) {
    if (t->probe->free_def) {
      t->probe->free_def(t->def);
    } else {
      free(t->def);
    }
  }
  return err;
}