public void createSMS(String web, com.afunms.polling.node.Tomcat node) {
    // 建立短信
    // 从内存里获得当前这个IP的PING的值
    Calendar date = Calendar.getInstance();
    try {
      if (!sendeddata.containsKey(web + ":" + node.getId())) {
        // 若不在,则建立短信,并且添加到发送列表里
        Smscontent smscontent = new Smscontent();
        String time = sdf.format(date.getTime());
        smscontent.setLevel("2");
        smscontent.setObjid(node.getId() + "");
        smscontent.setMessage(node.getIpAddress() + "的TOMCAT服务停止");
        smscontent.setRecordtime(time);
        smscontent.setSubtype("tomcat");
        smscontent.setSubentity("ping");
        smscontent.setIp(node.getIpAddress());

        // smscontent.setMessage("db&"+time+"&"+dbmonitorlist.getId()+"&"+db+"("+dbmonitorlist.getDbName()+" IP:"+dbmonitorlist.getIpAddress()+")"+"的数据库服务停止");
        // 发送短信
        SmscontentDao smsmanager = new SmscontentDao();
        smsmanager.sendURLSmscontent(smscontent);
        sendeddata.put(web + ":" + node.getId(), date);
      } else {
        // 若在,则从已发送短信列表里判断是否已经发送当天的短信
        Calendar formerdate = (Calendar) sendeddata.get(web + ":" + node.getId());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date last = null;
        Date current = null;
        Calendar sendcalen = formerdate;
        Date cc = sendcalen.getTime();
        String tempsenddate = formatter.format(cc);

        Calendar currentcalen = date;
        cc = currentcalen.getTime();
        last = formatter.parse(tempsenddate);
        String currentsenddate = formatter.format(cc);
        current = formatter.parse(currentsenddate);

        long subvalue = current.getTime() - last.getTime();
        if (subvalue / (1000 * 60 * 60 * 24) >= 1) {
          // 超过一天,则再发信息
          Smscontent smscontent = new Smscontent();
          String time = sdf.format(date.getTime());
          smscontent.setLevel("2");
          smscontent.setObjid(node.getId() + "");
          smscontent.setMessage(node.getAlias() + " (" + node.getIpAddress() + ")" + "的访问服务停止");
          smscontent.setRecordtime(time);
          smscontent.setSubtype("tomcat");
          smscontent.setSubentity("ping");
          smscontent.setIp(node.getIpAddress());
          // smscontent.setMessage("db&"+time+"&"+dbmonitorlist.getId()+"&"+db+"("+dbmonitorlist.getDbName()+" IP:"+dbmonitorlist.getIpAddress()+")"+"的数据库服务停止");
          // 发送短信
          SmscontentDao smsmanager = new SmscontentDao();
          smsmanager.sendURLSmscontent(smscontent);
          // 修改已经发送的短信记录
          sendeddata.put(web + ":" + node.getId(), date);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  public void createSMS(String mailserver, String mail_id, String errmsg, String mailstr) {
    // 建立短信
    // 从内存里获得当前这个IP的PING的值
    Calendar date = Calendar.getInstance();
    try {
      if (!sendeddata.containsKey(mailserver + ":" + mail_id)) {
        // 若不在,则建立短信,并且添加到发送列表里
        Smscontent smscontent = new Smscontent();
        smscontent.setMessage(errmsg);
        smscontent.setObjid(mail_id);
        Calendar _tempCal = Calendar.getInstance();
        Date _cc = _tempCal.getTime();
        String _time = sdf.format(_cc);
        smscontent.setRecordtime(_time);
        smscontent.setSubtype("mail");
        smscontent.setLevel(3 + "");
        // 发送短信
        SmscontentDao smsmanager = new SmscontentDao();
        smsmanager.sendURLSmscontent(smscontent);
        sendeddata.put(mailserver + ":" + mail_id, date);
      } else {
        // 若在,则从已发送短信列表里判断是否已经发送当天的短信
        Calendar formerdate = (Calendar) sendeddata.get(mailserver + ":" + mail_id);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date last = null;
        Date current = null;
        Calendar sendcalen = formerdate;
        Date cc = sendcalen.getTime();
        String tempsenddate = formatter.format(cc);

        Calendar currentcalen = date;
        cc = currentcalen.getTime();
        last = formatter.parse(tempsenddate);
        String currentsenddate = formatter.format(cc);
        current = formatter.parse(currentsenddate);

        long subvalue = current.getTime() - last.getTime();
        if (subvalue / (1000 * 60 * 60 * 24) >= 1) {
          // 超过一天,则再发信息
          Smscontent smscontent = new Smscontent();
          // String time = sdf.format(date.getTime());
          smscontent.setMessage(errmsg.replace("&", " "));
          smscontent.setObjid(mail_id);
          Calendar _tempCal = Calendar.getInstance();
          Date _cc = _tempCal.getTime();
          String _time = sdf.format(_cc);
          smscontent.setRecordtime(_time);
          smscontent.setSubtype("mail");
          smscontent.setLevel(3 + "");
          // 发送短信
          SmscontentDao smsmanager = new SmscontentDao();
          smsmanager.sendURLSmscontent(smscontent);
          // 修改已经发送的短信记录
          sendeddata.put(mailserver + ":" + mail_id, date);
        } else {
          // 则写声音告警数据
          // 向声音告警表里写数据
          AlarmInfo alarminfo = new AlarmInfo();
          alarminfo.setContent(errmsg.replace("&", " "));
          alarminfo.setIpaddress(mailstr);
          alarminfo.setLevel1(new Integer(2));
          alarminfo.setRecordtime(Calendar.getInstance());
          AlarmInfoDao alarmdao = new AlarmInfoDao();
          alarmdao.save(alarminfo);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }