Example #1
0
  // communicating with pingdomintegrator class
  @OnAlias("sendreqdel")
  public void sendreqdel(TeamchatAPI api) throws IOException {

    int i;
    String chks[] = new String[count - 1];
    int s = 1;
    for (i = 0; i < count - 1; i++) {

      chks[i] = api.context().currentReply().getField("Checks" + String.valueOf(s));
      s++;
    }

    s = 1;
    url = "https://api.pingdom.com/api/2.0/checks";
    pingdomintegrator ob1 = new pingdomintegrator();

    String resp = ob1.getChecks(Username, Password, App_key, url);
    Gson gson = new Gson();
    Checks checks = gson.fromJson(resp, Checks.class);

    int k = 0;

    int del[] = new int[count - 1];

    for (Check check : checks.getChecks()) {
      if (check.getHostname().equals(chks[k])) {

        del[k] = check.getId();
      } else {

        del[k] = 1;
      }
      k++;
    }

    k = 1;

    String respdel = ob1.delChecks(Username, Password, App_key, del);

    if (respdel.equals("Error")) {
      PrimaryChatlet prime = new PrimaryChatlet();
      api.perform(
          api.context()
              .currentRoom()
              .post(
                  prime.setQuestionHtml(
                      "<br /><b>Error :</b>"
                          + "<br /><b>Status Code: 403</b>"
                          + "<br /><b>StatusDesc: Forbidden</b>"
                          + "<br /><b>Something went wrong!</b>")));

    } else {
      PrimaryChatlet prime = new PrimaryChatlet();
      api.perform(
          api.context().currentRoom().post(prime.setQuestionHtml("<br /><b>" + respdel + "</b>")));
    }
  }
Example #2
0
  @OnAlias("sendreqcheck")
  public void sendreqcheck(TeamchatAPI api) throws IOException {

    int i;
    String chks[] = new String[count - 1];
    int s = 1;
    for (i = 0; i < count - 1; i++) {

      chks[i] = api.context().currentReply().getField("Checks" + String.valueOf(s));
      s++;
    }
    count = 1;
    s = 1;
    url = "https://api.pingdom.com/api/2.0/checks";
    pingdomintegrator ob1 = new pingdomintegrator();
    String resp = ob1.getChecks(Username, Password, App_key, url);

    Gson gson = new Gson();
    Checks checks = gson.fromJson(resp, Checks.class);

    int k = 0;
    String color;
    color = "#359FD8";
    // color="#CF0909";--red
    // color="#24970D";---green
    int len = chks.length;
    for (Check check : checks.getChecks()) {
      for (k = 0; k < len; k++) {
        if (check.getHostname().equals(chks[k])) {
          if (check.getStatus().equals("up")) {

            color = "#24970D";

          } else if (check.getStatus().equalsIgnoreCase("down")) {
            color = "#CF0909";
          }
          PrimaryChatlet prime1 = new PrimaryChatlet();
          prime1.setQuestionHtml(
              "<h4><b>Host Details "
                  + String.valueOf(s)
                  + ":</b></h4>"
                  + "<ul type=\"square\"; style=\"color:#359FD8\";><li><a1 style=\"color:black\";><b>Name- </b></a1><a2 style=\"color:#359FD8\";>"
                  + check.getName()
                  + "</a2></li><li><a3 style=\"color:black\";><b>Hostname- </b></a3><a4 style=\"color:#359FD8\";>"
                  + check.getHostname()
                  + "</a4></li><li><a5 style=\"color:black\";><b>Status - </b></a5><a6 style=\"color:"
                  + color
                  + "\";>"
                  + check.getStatus()
                  + "</a6></li><li><a7 style=\"color:black\";><b>Last Response Time - </b></a7><a8 style=\"color:#359FD8\";>"
                  + check.getLastresponsetime()
                  + " ms"
                  + "</a8></li><li><a9 style=\"color:black\";><b>Type - </b></a9><a10 style=\"color:#359FD8\";>"
                  + check.getType()
                  + "</a10></li></ul>");
          api.perform(api.context().currentRoom().post(prime1));

          s++;
        }
      }
    }

    s = 1;
  }
Example #3
0
  @OnKeyword("deletecheck")
  public void deletecheck(TeamchatAPI api) throws IOException, SQLException {
    String rmid;
    count = 1;
    rmid = api.context().currentRoom().getId();
    DBHandler ob4 = new DBHandler();
    boolean flag;
    flag = ob4.roomchk(rmid);

    if (flag == false) {
      PrimaryChatlet prime = new PrimaryChatlet();
      prime.setQuestionHtml(
          "<br /><b>First you have to sign in!!</b>"
              + "<br /><b>Note: </b><a1  style=\"color:#359FD8\";>For Signing in type \"login\" command</a1>");

      api.perform(api.context().currentRoom().post(prime));
    } else {
      DBHandler ob5 = new DBHandler();
      String[] usrpassapp = ob5.getusrpassapp(rmid);
      Username = usrpassapp[0];
      Password = usrpassapp[1];
      App_key = usrpassapp[2];
      url = "https://api.pingdom.com/api/2.0/checks";
      pingdomintegrator ob1 = new pingdomintegrator();
      String resp = ob1.getChecks(Username, Password, App_key, url);

      if (resp.equals("Error")) {
        PrimaryChatlet prime = new PrimaryChatlet();
        api.perform(
            api.context()
                .currentRoom()
                .post(
                    prime.setQuestionHtml(
                        "<br /><b>Error :</b>"
                            + "<br /><b>Status Code: 403</b>"
                            + "<br /><b>StatusDesc: Forbidden</b>"
                            + "<br /><b>Something went wrong!</b>")));

      } else {

        Gson gson = new Gson();
        Checks checks = gson.fromJson(resp, Checks.class);
        Form fo = api.objects().form();

        for (Check check : checks.getChecks()) {

          fo.addField(
              api.objects()
                  .select()
                  .name("Checks" + String.valueOf(count))
                  .label("Select check " + String.valueOf(count) + ":")
                  .addOption(check.getHostname())
                  .addOption("none"));

          count++;
        }

        api.perform(
            api.context()
                .currentRoom()
                .post(
                    new PrimaryChatlet()
                        .setQuestionHtml("<br /><b>Select Checks from below :</b>")
                        .setReplyScreen(fo)
                        .setReplyLabel("Enter")
                        .alias("sendreqdel")));
      }
    }
  }
Example #4
0
  @OnKeyword("ping")
  public void ping(TeamchatAPI api) throws IOException, SQLException {
    String rmid;
    count = 1;
    // getting roomid
    rmid = api.context().currentRoom().getId();
    DBHandler ob4 = new DBHandler();
    boolean flag;
    flag = ob4.roomchk(rmid);
    // checking if roomid is available in the database.If it is available then user will be logged
    // in automatically n flag will become true else false
    if (flag == false) {
      PrimaryChatlet prime = new PrimaryChatlet();
      prime.setQuestionHtml(
          "<br /><b>First you have to sign in!!</b>"
              + "<br /><b>Note: </b><a1  style=\"color:#359FD8\";>For Signing in type \"login\" command</a1>");

      api.perform(api.context().currentRoom().post(prime));
    } else {
      DBHandler ob5 = new DBHandler();
      String[] usrpassapp = ob5.getusrpassapp(rmid);
      Username = usrpassapp[0];
      Password = usrpassapp[1];
      App_key = usrpassapp[2];
      url = "https://api.pingdom.com/api/2.0/checks";
      pingdomintegrator ob1 = new pingdomintegrator();
      String resp = ob1.getChecks(Username, Password, App_key, url);

      // error if there is some issue in the authentication.

      if (resp.equals("Error")) {
        PrimaryChatlet prime = new PrimaryChatlet();
        api.perform(
            api.context()
                .currentRoom()
                .post(
                    prime.setQuestionHtml(
                        "<br /><b>Error :</b>"
                            + "<br /><b>Status Code: 403</b>"
                            + "<br /><b>StatusDesc: Forbidden</b>"
                            + "<br /><b>Something went wrong!</b>")));

      } else {

        // parsing a json like this

        // {
        // "checks": [
        // {
        // "id": 1650784,
        // "created": 1435769579,
        // "name": "google",
        // "hostname": "www.google.com",
        // "use_legacy_notifications": true,
        // "resolution": 1,
        // "type": "http",
        // "lasttesttime": 1435806884,
        // "lastresponsetime": 167,
        // "status": "up",
        // "probe_filters": []
        // },
        // {
        // "id": 1650785,
        // "created": 1435769756,
        // "name": "Teamchat",
        // "hostname": "www.teamchat.com",
        // "use_legacy_notifications": true,
        // "resolution": 1,
        // "type": "http",
        // "lasttesttime": 1435806881,
        // "lastresponsetime": 725,
        // "status": "up",
        // "probe_filters": []
        // },
        // {
        // "id": 1650787,
        // "created": 1435769804,
        // "name": "Interns Teamchat",
        // "hostname": "interns.teamchat.com",
        // "use_legacy_notifications": true,
        // "resolution": 1,
        // "type": "http",
        // "lasterrortime": 1435806882,
        // "lasttesttime": 1435806882,
        // "lastresponsetime": 0,
        // "status": "down",
        // "probe_filters": []
        // }
        // ],
        // "counts": {
        // "total": 3,
        // "limited": 3,
        // "filtered": 3
        // }
        // }

        Gson gson = new Gson();
        Checks checks = gson.fromJson(resp, Checks.class);
        Form fo = api.objects().form();

        for (Check check : checks.getChecks()) {

          fo.addField(
              api.objects()
                  .select()
                  .name("Checks" + String.valueOf(count))
                  .label("Select check " + String.valueOf(count) + ":")
                  .addOption(check.getHostname())
                  .addOption("none"));

          count++;
        }

        api.perform(
            api.context()
                .currentRoom()
                .post(
                    new PrimaryChatlet()
                        .setQuestionHtml("<br /><b>Select Checks from below :</b>")
                        .setReplyScreen(fo)
                        .setReplyLabel("Enter")
                        .alias("sendreqcheck")));
      }
    }
  }