다이얼에서
*#546368#*460#
하면 히든메뉴 진입...
매번 헤매느니 한번 적자..
2017년 7월 14일 금요일
2017년 7월 4일 화요일
Java로 SQL Agent Log에서 잡다한 거 빼고 보기
0. 일단.. SQL Server Profiler 한 바퀴 돌려주고
1. xml로 저장해서 java로 parsing 한다.
2. 내 맘대로 짠거임.. 알아서 변용하도록
3. 남자답게!! 출처는 밝히자!!
1. xml로 저장해서 java로 parsing 한다.
2. 내 맘대로 짠거임.. 알아서 변용하도록
3. 남자답게!! 출처는 밝히자!!
package com.lifebook.util; import java.io.File; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class parseSqlLog { private static Connection conn = null; private static PreparedStatement psmt = null; private static ResultSet rs = null; private static String conUrl = "니꺼 jdbc 접속 문자열!"; private static String[] chkFilterList = { "SQL:BatchCompleted", "Trace Stop", "RPC:Completed", "select @@microsoftversion", "select convert(sysname, serverproperty(N'servername'))", "SET TEXTSIZE 1024", "SELECT ISNULL(SUSER_SNAME(), SUSER_NAME())", "SELECT N'Testing Connection...'", "SET NO_BROWSETABLE ON", "SET NO_BROWSETABLE OFF", "set fmtonly off", "select serverproperty(N'instancename')", "ServerProperty('", "SERVERPROPERTY", "@@microsoftversion", "#err_log_tmp er", "SERVERPROPERTY(N'", "SET LOCK_TIMEOUT", "EXEC master.dbo.xp_readerrorlog", "CAST(serverproperty(N'Servername') AS sysname)", "DECLARE @edition sysname; SET @edition = cast(SERVERPROPERTY(N'EDITION') as sysname)", "select value_in_use from sys.configurations where configuration_id", "select is_srvrolemember('sysadmin') * 1 +is_srvrolemember('serveradmin') * 2 +is_srvrolemember('setupadmin') * 4 +is_srvrolemember('securityadmin') * 8 +is_srvrolemember('processadmin') * 16 +is_srvrolemember('dbcreator') * 32 +is_srvrolemember('diskadmin') * 64+ is_srvrolemember('bulkadmin') * 128", "select SERVERPROPERTY(N'servername')", "EXECUTE msdb.dbo.sp_sqlagent_log_jobhistory @job_id = 0xC8FAC217480CAB478E3BB07AB02962E9", "BEGIN TRAN UPDATE msdb.dbo.sysjobsteps SET last_run_outcome" }; public static void main(String[] args) { // TODO Auto-generated method stub try { File fXmlFile = new File("E:\\workspace\\parseSqlLog\\src\\com\\lifebook\\util\\20170703.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); System.out.println("----------------------------"); NodeList nList = doc.getElementsByTagName("Events"); double rowCnt = 0d; for (int temp = 0; temp < nList.getLength(); temp++) { System.out.println("item:::" + nList.item(temp).getChildNodes().getLength()); Node nNode = nList.item(temp); NodeList cList = nNode.getChildNodes(); for(int cCnt = 0 ; cCnt < cList.getLength() ; cCnt ++){ Node cNode = cList.item(cCnt); if (cNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) cNode; if(chkString(eElement.getAttribute("name").toString())){ //System.out.println("name : " + eElement.getAttribute("name")); NodeList colsList = cNode.getChildNodes(); for(int colCnt = 0 ; colCnt < colsList.getLength() ; colCnt ++){ Node colNode = colsList.item(colCnt); //System.out.println(colNode.getNodeName()); if (colNode.getNodeType() == Node.ELEMENT_NODE) { Element colEle = (Element) colNode; //System.out.println("cols name : " + colEle.getAttribute("name")); if(colEle.getAttribute("name").toString().equals("TextData")){ if(chkString(colEle.getTextContent())){ rowCnt ++; //System.out.println(rowCnt + "::::::" + colEle.getTextContent()); //System.out.println(colEle.getTextContent().toLowerCase().indexOf("select")); chkDbCmd(colEle.getTextContent()); if(colEle.getTextContent().toLowerCase().indexOf("select")>=0){ //System.out.println(rowCnt + "::::::" + colEle.getTextContent()); //chkDbCmd(colEle.getTextContent()); } } } } } } } } } } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static boolean chkString(String chkStr){ boolean rtnBool = true; for(int chkCnt = 0 ; chkCnt < chkFilterList.length ; chkCnt++){ //System.out.println(chkStr); //System.out.println(chkFilterList[chkCnt]); //System.out.println(chkStr.indexOf(chkFilterList[chkCnt])); if(chkStr.indexOf(chkFilterList[chkCnt]) >= 0){ rtnBool = false; break; } } return rtnBool; } public static void chkDbCmd(String sql){//얘는 SQL 실행시 오류 발생하는지 알아볼라고 만든거임.. try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); conn = DriverManager.getConnection(conUrl); psmt = conn.prepareStatement(sql); rs = psmt.executeQuery(); rs.close(); psmt.close(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block System.out.println(sql); e.printStackTrace(); } finally { if (conn != null) { try { conn.close(); } catch (Exception e) { } } if (psmt != null) { try { psmt.close(); } catch (Exception e) { } } if (rs != null) { try { rs.close(); } catch (Exception e) { } } } } }
SQL AGENT 에서 Application Name 으로 프로시저 찾기
먼저 하단 함수 생성
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[GetJobIdFromProgramName] ( @program_name nvarchar(128) ) RETURNS uniqueidentifier AS BEGIN DECLARE @start_of_job_id int SET @start_of_job_id = CHARINDEX('(Job 0x', @program_name) + 7 RETURN CASE WHEN @start_of_job_id > 0 THEN CAST( SUBSTRING(@program_name, @start_of_job_id + 06, 2) + SUBSTRING(@program_name, @start_of_job_id + 04, 2) + SUBSTRING(@program_name, @start_of_job_id + 02, 2) + SUBSTRING(@program_name, @start_of_job_id + 00, 2) + '-' + SUBSTRING(@program_name, @start_of_job_id + 10, 2) + SUBSTRING(@program_name, @start_of_job_id + 08, 2) + '-' + SUBSTRING(@program_name, @start_of_job_id + 14, 2) + SUBSTRING(@program_name, @start_of_job_id + 12, 2) + '-' + SUBSTRING(@program_name, @start_of_job_id + 16, 4) + '-' + SUBSTRING(@program_name, @start_of_job_id + 20,12) AS uniqueidentifier) ELSE NULL END END --FUNCTION
에이전트 로그에서
SELECT * FROM msdb.dbo.sysjobs WHERE job_id = dbo.GetJobIdFromProgramName ('SQLAgent - TSQL JobStep (Job 0xC8FAC217480CAB478E3BB07AB02962E9 : Step 2) ')
같이 검색하면 짜잔~~! 나옴.
이거 땜시로 오늘 완전 개고생 함..
2017년 6월 12일 월요일
6. JAVA로 날씨정보, 대기정보 호출...
1. 대기정보 분해하기
2. 수치 값이 오기에, 한국 사이트에서 값 구간에 대한 문자열 값을 보고 출력해 줌.
public static void parseAir(String airInfo) { try { ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(airInfo); System.out.println(root.path("data")); System.out.println(root.path("data").path("aqi")); String aqiVal = root.path("data").path("aqi").toString(); int aqi = Integer.parseInt(aqiVal); String aqiNm = ""; if(aqi <= 0 && aqi >=50) aqiNm = "좋음"; if(aqi <= 51 && aqi >=100) aqiNm = "보통"; if(aqi <= 101 && aqi >=150) aqiNm = "민감군영향"; if(aqi <= 151 && aqi >=200) aqiNm = "나쁨"; if(aqi <= 201 && aqi >=300) aqiNm = "매우나쁨"; if(aqi < 300) aqiNm = "위험"; System.out.println(aqiNm); //System.out.println(root.path("result")); /* * AQI 지수구분 구간의미 0 - 50 좋음 대기오염 관련 질환자군에서도 영향이 유발되지 않을 수준 51 -100 보통 환자군에게 만성 노출시 경미한 영향이 유발될 수 있는 수준 101-150 민감군영향 환자군 및 민감군에게 유해한 영향이 유발될 수 있는 수준 151-200 나쁨 환자군 및 민감군(어린이, 노약자 등)에게 유해한 영향 유발, 일반인도 건강상 불쾌감을 경험할 수 있는 수준 201-300 매우나쁨 환자군 및 민감군에게 급성 노출시 심각한 영향 유발, 일반인도 약한 영향이 유발될 수 있는 수준 300+ 위험 환자군 및 민감군에게 응급 조치가 발생되거나, 일반인에게 유해한 영향이 유발될 수 있는 수준 * */ } catch (JsonProcessingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
5. JAVA로 날씨정보, 대기정보 호출...
1. 날씨정보 분해하기
2. json 사용할 줄 알면 다 하는 그거..
3. jackson 2.8.9 사용함.
2. json 사용할 줄 알면 다 하는 그거..
3. jackson 2.8.9 사용함.
public static void parseWeather(String weatherInfo) { //System.out.println(weatherInfo); try { ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(weatherInfo); //System.out.println(root.path("weather")); System.out.println(root.path("weather").path("yesterday").get(0).findValue("sky")); //여러 정보가 오지만.. 난 날씨만 필요함 System.out.println(root.path("result")); } catch (JsonProcessingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
4. JAVA로 날씨정보, 대기정보 호출...
1. url에서 읽어온 InputStream을 String 변환 공통 함수
2. 인터넷에서 대충 줒은거 개조했음.
2. 인터넷에서 대충 줒은거 개조했음.
public static void printByInputStream(InputStream is, String tgtMode) { byte[] buf = new byte[2048]; StringBuffer sb = new StringBuffer(); int len = -1; try { while ((len = is.read(buf, 0, buf.length)) != -1) { sb.append(new String(buf, 0, len)); } System.out.println(sb.toString()); if(tgtMode.equals("weather")){ parseWeather(sb.toString()); }else{ parseAir(sb.toString()); } } catch (IOException e) { e.printStackTrace(); } }
3. JAVA로 날씨정보, 대기정보 호출...
1. 대기정보값 받기..
public static void getAir(String lat, String lon){ httpclient = HttpClients.createDefault(); String callUrl = setLocation(lat, lon, "air"); try { HttpGet httpGet = new HttpGet(callUrl); //대기정보 url 호출... httpGet.addHeader("appKey", appKeyId); System.out.println(httpGet.getURI()); System.out.println("[Executing request]: " + httpGet.getRequestLine()); HttpResponse response = httpclient.execute(httpGet); //System.out.println(response.toString()); InputStream in2; in2 = response.getEntity().getContent(); printByInputStream(in2 , "air"); in2.close(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { } }
피드 구독하기:
글 (Atom)
-
어찌어찌 번역은 다 해서 올려 놓았으나.. 회사에선 다음 빌드까지 기다려 주지 않기에 번역을 다운로드 해 봤다.. 구축한 웹 사이트에 로그인을 해보고.. 언어 설정으로 가 보았으나... 어라??? 한글 선택이 없다!!! 이거 뭐지??...
-
업무 처리하다 보니.. 엑셀로 데이터를 넘겨 받음.. 양이 좀 많아서.. 중복 데이터 삭제 기능 검색울 해 보았으나.. 엑셀의 중복 제거 기능만 나옴... 오픈오피스는 아무래도 마이너해서 그런가.. 한글로 검색 말고.. 영어로 구글링...
-
모든 일의 시작은.. 최근에 JRE를 업데이트를 했는데.. 32-Bit로 update가 된 듯... Eclipse 실행시 !ENTRY org.eclipse.osgi 4 0 2015-03-31 14:21:48.411 !MESSAGE Ap...
[낯선] 2026.06.20 이태원 MZK MuzikBar 공연
간만의 공연 이태원 비틀즈가 이전하여 MZK MuzikBar 로 새 단장 오픈을 한 뒤로 2번째 공연 새 베이시스트가 합류한 뒤로 첫 공연이기도 함.. 이래저래 틀린 부분도 많지만.. 그래도 간만에 그럭저럭 잘했다.. https://www.youtub...