2016년 9월 19일 월요일

PHP를 활용하여 Jira Issues 출력해보기

업무에 빈번하게 활용하고 있는 Jira를 내 취향대로 일목요연하게 정리해보고 싶을 때 다음과 같은 방법으로 웹페이지를 만들어 출력해볼수 있습니다.  핵심적인 부분만 샘플로 추려보면

1. Connection 설정
2. Issues 가져오기
3. HTML로 출력하기

순서입니다.

개인적으로 나중에 알아보기 편하려고 function으로 구분해두었는데, 개발자가 아님을 감안하여 봐주시기를 바라겠습니다.


[ JIRA 연결을 위한 초기 세트 ]
  <?php

  function initConnection() {
      $username = 'JIRA유저아이디';
      $password = 'JIRA유저패스워드';

      global $curl;

      $curl = curl_init();
      curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  }

[ Issues 목록 가져오기 (생성일 순으로 정렬해서 최대 500개) ]
  function listIssues() {
      echo "<table>";
      global $curl, $issues;

      curl_setopt($curl, CURLOPT_URL,
          "http://JIRA서버:8080/rest/api/2/search?startIndex=0&jql=".
          "+order+by+created+asc".
          "&maxResults=500");
  }

[ 가져온 Issues 출력하기 (Summary,Status,Name,Created,Assignee,Reporter과 Comment 내용) ]
  function displayIssues() {
      echo "<table border='-1'>";
      echo "<tr><th width='120'>Issue Number</th>
                <th width='450'>Summary</th>
                <th width='100'>Status</th>
                <th width='100'>Priority</th>
                <th width='200'>Create Date</th>
                <th width='80'>Assignee</th>
                <th width='80'>Reporter</th>
           </tr>";
      global $curl, $issues;

      $issues = json_decode(curl_exec($curl), true);
      foreach ($issues['issues'] as $issue) {
          echo "<tr>";
          echo "<td bgcolor=#eee>"; echo "<a href='"; print_r("http://JIRA서버:8080/browse/".$issue['key']); echo "'>";
              print_r($issue['key']);
          echo "</a></td>";
          echo "<td bgcolor=#eee><b>"; print_r($issue['fields']['summary']); echo "</b></td>";
          echo "<td bgcolor=#ccc><b>"; print_r($issue['fields']['status']['name']); echo "</b></td>";
          echo "<td bgcolor=#eee>"; print_r($issue['fields']['priority']['name']); echo "</td>";
          echo "<td bgcolor=#eee>"; print_r($issue['fields']['created']); echo "</td>";
          echo "<td bgcolor=#eee><b>"; print_r($issue['fields']['assignee']['displayName']); echo "</b></td>";
          echo "<td bgcolor=#eee>"; print_r($issue['fields']['reporter']['displayName']); echo "</td>";
          echo "<tr><td colspan=7>";

          $key = $issue['key'];
          curl_setopt($curl, CURLOPT_URL, "http://JIRA서버:8080/rest/api/2/issue/$key/comment");

          $comments = json_decode(curl_exec($curl), true);

          foreach ($comments['comments'] as $comment) {
              echo "<p>&raquo;&nbsp"; print_r($comment['body']); echo "</p>";
          }
          echo "<font color=#ccc><i>"; print_r($issue['fields']['updated']); echo "</i></font><br>";
          echo "</tr>";
      }
      echo "</table>";
  }

[ 그리고 출력하기 ]
  initConnection();
  listIssues();
  displayIssues();

  ?>


php 파일 하나로 만들어서 호출해보시면 됩니다.  출력 형태를 다양하게 만들어보세요.

2016년 3월 15일 화요일

Amazon NAT Gateway 모니터링

초기 Amazon 환경에서는 NAT AMI EC2로 NAT 시스템을 구축해왔습니다.

[NAT 인스턴스]


그리고 최근들어 Amazon이 NAT Gateway 서비스를 런칭하였고, 사용자들이 차츰 안정성과 관리성을 고려하여 Amazon NAT Gateway 서비스로 전환하고 있는 추세입니다.



이렇게 전환한 NAT 환경 또한 모니터링을 고려해야 할텐데, Flow Logs와 API 명령을 사용해 손쉽게 대비할수 있습니다.

[Flow Logs 소개 및 설정]

Flow Logs를 사용한다면 지정한 프로토콜 및 서비스 상태에 따라 Notification도 가능합니다.

[API 명령 예]
# aws ec2 describe-nat-gateways --output=text --nat-gateway-id nat-xxxxxxxxxxxxxx
※ 상태 (pending | failed | available | deleting | deleted)

또, API 명령을 응용해서 NAT Gateway의 상태도 확인 할수도 있습니다.  응용한다면 각종 모니터링 툴을 통해서 관리할수 있겠네요.


그럼 간단히 API 명령으로 상태를 리턴받는 스크립트를 예로 들어보겠습니다.

[상태 확인 스크립트]
#!/bin/bash
# ./get_natgateway.sh [PROFILE-NAME] [REGION] [NAT-ID]

config=${1}
region=${2}
value=${3}

result=$(
/usr/local/bin/aws ec2 describe-nat-gateways --profile=${config} --region=${region} \
--nat-gateway-id ${value} \
--query 'NatGateways[0].State' \
--output text
)

printf '%s' ${result}

exit 1


무척 간단하네요.  조금 더 고급지게 공유해야 할텐데 시간이 허락치 않아서.. 죄송죄송~