ヘルプ アプリケーションログ管理 ログのエクスポートと共有

ログのエクスポートと共有

Site24x7はログ管理機能を備えており、ログデータをエクスポートして分析/共有することが可能です。
ログエントリをCSV形式でダウンロードできるため、レポート作成、トラブルシューティング、より深い洞察を柔軟に行うことができます。
エクスポートできるログエントリの数はサブスクリプションプランによって異なります。上位プランではエクスポートごとに最大100万エントリがサポートされ、その他のプランでは最大10万エントリがサポートされます。

ログのエクスポート

ログをエクスポートする方法

  1. Site24x7にログイン
  2. [アプリケーションログ]に移動
  3. クエリを入力して[Enter]キーをクリックするか、検索アイコン(Search-icon )をクリック
  4. 共有アイコン(Share-logs)をクリック
    データを検索して表示していない場合、共有オプションは使用できません。
  5. ダウンロードもしくはエクスポートするログエントリを選択
    1. 読み込まれたデータ:クライアントに現在読み込まれているログエントリをCSVまたはPDF形式でダウンロード
    2. すべてのエントリ:最大10,000件のログエントリをCSV形式でダウンロード
    3. エクスポート(上限エントリ数まで):ログデータをCSV形式でエクスポート
  6. [ダウンロード]ボタンをクリック
  • PDF形式は、ロードされたデータオプションでのみ使用できます。CSV形式は、すべてのオプションで使用できます。
  • エクスポートは、Professionalプラン(最大10万エントリ)およびEnterpriseプラン(最大100万エントリ)アカウントでのみ利用できます。
  • エクスポートオプションにアクセスできるのは、管理者、スーパー管理者、オペレーターの権限を持つユーザーのみです。

エクスポートの履歴

[履歴]タブには、過去に行ったすべてのログエクスポートの記録が表示されます。
次の操作が可能です。

  • 各エクスポートの日時を表示
  • 過去にエクスポートしたログデータを再ダウンロード

エクスポートされたログデータは5日間保持されます。5日間以内であれば再度ダウンロードが可能です。

メールオプション

ログをPDF形式でエクスポートし、メールで共有できます
※これは現在インターフェースに読み込まれているログに対してのみサポート可能です。
このオプションは、システムから直接ログデータを共有したい際に便利です。

REST API経由で100万エントリを超えるログをエクスポートする

100万件以上のログエントリーをエクスポートする必要がある場合、以下のスクリプトを使用して、REST API経由でログをダウンロードすることが可能です。
各API呼び出しで取得されるレコードは1,000件だけなので、ダウンロードプロセスが遅くなる可能性があります。
スクリプトは、APIを再帰的に呼び出してデータをCSVファイルに書き込むことでこれを処理しています。

ログをダウンロードするためにスクリプトを実行します。
必ずスクリプトの「USER INPUTS」セクションを更新してからスクリプトを実行してください。

import os
##### USER INPUTS ###############################################
client_id = "1000.XXXXX"
client_secret = "XXXXXXXX"
code = "1000.XXXXX.YYYYYY"
#format DD-MM-YYYY HH:mm:ss
start_time = "11-11-2024 00:00:01"
end_time = "11-11-2024 23:59:59"
#change the query and delimit the characters wherever applicable
query = "logtype=\"Infrastructure Events\""
#change the location to where the output must be stored
# if the following value is to be changed give the value as string example  "/home/user/Documents/Project/Bulk_Export"
destination_path = os.getcwd() 
#change the name of the output file
filename = "output"
##################################################################
import time
import re
try:
    import requests
except ImportError:
    try:
        os.system('python3 -m pip install requests')
        import requests
    except Exception as e:
        print(e)
global access_token
path = os.path.join(destination_path, "output")
if not os.path.exists(path):
    os.mkdir(path)
else:
    for each_file in os.listdir(path):
        if not each_file.endswith(".txt"):
            os.remove("{}/{}".format(path,each_file))
access_token_payload = {
    "client_id" : client_id,
    "client_secret" : client_secret
}
auth_token_url = "https://accounts.zoho.com/oauth/v2/token?"

def get_data():
    
    global access_token
    
    data_exclusion = ("_zl","s247","inode")
    query_params = {"query":query}
    
    print("Starting export")
    
    while True:
        
        print("Executing query")
        r = requests.get('https://www.site24x7.com/api/applog/search/{}/{}/1-1000/desc?'.format(start_time,end_time), headers={'Authorization': access_token},params=query_params)
        if r.status_code == 200 and (int(r.json()["data"]["ErrorCode"]) == 0):                
            
            print("Downloading...")
            
            f = open("{}/{}.csv".format(path,filename), "a")
            total = int(r.json()["data"]["numFound"])
            csv_headers = []
            for iterations in range(0,((total // 1000) + ((total % 1000) > 0))):
                response = requests.get("https://www.site24x7.com/api/applog/search/{}/{}/{}-{}/desc?".format(start_time,end_time,(iterations*1000)+1,(iterations+1)*1000), headers={'Authorization':access_token },params=query_params)
                
                if response.status_code == 200 and (int(r.json()["data"]["ErrorCode"]) == 0):
                    
                    if iterations == 0:
                        for field_key in response.json()['data']['docs'][0]:
                            if not field_key.startswith(data_exclusion):
                                csv_headers.append(field_key)
                        f.write(','.join(csv_headers)+"\n")
                    
                    for rows in response.json()['data']['docs']:
                        rowData = ''
                        for field_key in csv_headers:
                            rowData =  str(rowData) + '"' +str(rows[field_key]).replace('"','""') +'"' + ','
                        rowData = rowData.rstrip(rowData[-1])
                        f.write(rowData+"\n")
                time.sleep(1)
            f.close()
            print("Export successfully completed")
            break
        
        elif r.status_code == 401:
            get_access_token()
        
        else:
            print("Error while retrieving data")
            break

def get_access_token():
    
    global access_token
    access_token_response = requests.post(url=auth_token_url,params=access_token_payload)
    if access_token_response.status_code == 200 and ("error" not in str(access_token_response.content)):
        access_token = "Zoho-oauthtoken " + access_token_response.json()["access_token"]
    else:
        print("Error while fetching access token - ", str(access_token_response.content))
        exit()
def get_refresh_token():
    refresh_token_payload = access_token_payload.copy()
    refresh_token_payload.update({
        "grant_type" : "authorization_code",
        "code" : code
        })
    
    refresh_token_response = requests.post(url=auth_token_url,params=refresh_token_payload)
    
    if refresh_token_response.status_code == 200 and ("error" not in str(refresh_token_response.content)):
        access_token_payload["grant_type"] = "refresh_token"
        access_token_payload["refresh_token"] = refresh_token_response.json()["refresh_token"]
        rt_file = open("{}/{}.txt".format(path,"refresh_token"), "w")
        rt_file.write(access_token_payload["refresh_token"])
        rt_file.close
    else:
        print("Error while fetching refresh token - ",str(refresh_token_response.content))
        exit()
if __name__ == "__main__":  
    if not os.path.exists("{}/refresh_token.txt".format(path)):
        get_refresh_token()
    else:
        access_token_payload["grant_type"] = "refresh_token"
        access_token_payload["refresh_token"] = open("{}/refresh_token.txt".format(path), 'r').read()
    get_access_token()
    get_data()
  

関連