#!/usr/local/bin/python3 Author : Leegin Bernads T.S #Script to fetch the details from New Relic from nrql.api import NRQL import pandas as pd import gspread from oauth2client.service_account import ServiceAccountCredentials #Credentials for running the insight query. nrql = NRQL() nrql.api_key = '<NRQL-API-KEY>' nrql.account_id = '<NR-ACCOUNT-ID>' #Insight query to retieve the required information about the application print("Running NRQL query and fetching the data........") req = nrql.query("FROM NrDailyUsage SELECT count(*) WHERE productLine='APM' AND usageType='Application' FACET consumingAccountId, apmAppId, apmAppName, apmAgentVersion, apmLanguage SINCE 1 day ago LIMIT 2000") #empty list to store all the lists(list of lists) item = [] print("Preparing the sheet from which all the application details can be seen.......") for k in req['facets']: item.append(k['name']) df = pd.DataFrame(item, columns =['Account_id','App_id','App_name','Agent_version','App_Language']) df['New_relic URL']=df.apply(lambda x:'https://rpm.newrelic.com/accounts/%s/applications/%s' % (x['Account_id'],x['App_id']),axis=1) # Function to convert numbers to letters (1->A, 2->B, ... 26->Z, 27->AA, 28->AB...)
# v 2.0 # # Made by Yan Hrushchynskyi 2020 #--------------------------------------------------------------------------- #!/usr/local/bin/python3 from nrql.api import NRQL from pandas import DataFrame import datetime import getpass username = getpass.getuser() nrql = NRQL() nrql.api_key = 'xA*********************' nrql.account_id = '1***66' since = ' SINCE 1 hours ago' print('Coral Tech KPI checking. This process will take up to 1 minute') print('====================================') print("Response time section") req1 = nrql.query( "SELECT average(totalTime) from Transaction where appName = 'CR-SPT-BPP-MBFE-DBLN-PRD0' and `request.uri` = '/Proxy/auth/user' AND request.method = 'POST'" + since) for a in req1['results']: r1 = round(a['average'], 3) req2 = nrql.query( "SELECT average(totalTime) from Transaction where appName = 'CR-SPT-BPP-MBFE-DBLN-PRD0' AND request.method = 'POST' AND request.uri = '/Proxy/v1/placeBet'" + since) for a in req2['results']: r2 = round(a['average'], 3)
# Script allows to close violations in New Relic in case affected host was # terminated in AWS # # v 2.0 # # Made by Yan Hrushchynskyi 2020 #--------------------------------------------------------------------------- #!/usr/bin/env python from nrql.api import NRQL import requests nrql = NRQL() nrql.api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx' nrql.account_id = '1641266' rest_api = 'xxxxxxxxxxxxxxxxxx' arr2 = [] arr3 = [] #executing all opened violations req1 = nrql.query( "SELECT entity.name, id FROM AlertViolationsSample WHERE policy_name LIKE '%_%Lviv%' and policy_name not LIKE '%hlv%' and priority IN ('Critical', 'Warning') SINCE 6 hours ago LIMIT MAX" ) for i in req1['results']: arr1 = i['events'] #executing all events from Ec2Instance provider with 'Agent disconnected' status req2 = nrql.query( "SELECT entityName FROM InfrastructureEvent WHERE provider = 'Ec2Instance' and summary = 'Agent disconnected' AND environment = 'PRD0' SINCE 6 hours ago LIMIT MAX" ) for i in req2['results']: