Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 45 additions & 35 deletions ArtifactoryLogParser/artifactory.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,58 @@
import sys
import colorama
from colorama import Fore, Back, Style
import operator

if len(sys.argv) !=2:
print('Usage: python artifactory.py artifactory.log')
sys.exit(0)


errors = []
warnings = []
debug = []
readfile = sys.argv[1]
i = 0
with open(readfile) as f:
for line in f:
if "WARN" in line:
try:
regex = '^([-0-9]+ [:0-9]+,[0-9]+) \[([-a-zA-Z0-9]+)\] \[([A-Z]+) *\] \(([.a-zA-Z0-9]+):([0-9]+)\) - (.*)$'
match = re.search(regex,line.encode('ascii'),flags = 0)
print Fore.RED + "WARNING:" + (match.group(6))

except Exception:
pass

with open(readfile) as f:
for line in f:
if "ERROR" in line:
try:
regex = '^([-0-9]+ [:0-9]+,[0-9]+) \[([-a-zA-Z0-9]+)\] \[([A-Z]+) *\] \(([.a-zA-Z0-9]+):([0-9]+)\) - (.*)$'
match = re.search(regex,line.encode('ascii'),flags = 0)
print Fore.YELLOW + "ERROR:" + (match.group(6))

except Exception:
pass

with open(readfile) as f:
for line in f:
if "INFO" in line:

def readlogs():
with open(readfile) as f:
for line in f:
try:
regex = '^([-0-9]+ [:0-9]+,[0-9]+) \[([-a-zA-Z0-9]+)\] \[([A-Z]+) *\] \(([.a-zA-Z0-9]+):([0-9]+)\) - (.*)$'
match = re.search(regex,line.encode('ascii'),flags = 0)
print Fore.GREEN + "INFO:" + (match.group(6))

if "WARN" in line:
regex = '^([-0-9]+ [:0-9]+,[0-9]+) \[([-a-zA-Z0-9]+)\] \[([A-Z]+) *\] \(([.a-zA-Z0-9]+):([0-9]+)\) - (.*)$'
match = re.search(regex,line.encode('ascii'),flags = 0)
print Fore.RED + (match.group(6))
warnings.append(match.group(6)[:40])

elif "ERROR" in line:
regex = '^([-0-9]+ [:0-9]+,[0-9]+) \[([-a-zA-Z0-9]+)\] \[([A-Z]+) *\] \(([.a-zA-Z0-9]+):([0-9]+)\) - (.*)$'
match = re.search(regex,line.encode('ascii'),flags = 0)
print Fore.YELLOW + (match.group(6))
errors.append(match.group(6)[:40])
elif "INFO" in line:
regex = '^([-0-9]+ [:0-9]+,[0-9]+) \[([-a-zA-Z0-9]+)\] \[([A-Z]+) *\] \(([.a-zA-Z0-9]+):([0-9]+)\) - (.*)$'
match = re.search(regex,line.encode('ascii'),flags = 0)
print Fore.GREEN + (match.group(6))
elif "DEBUG" in line:
regex = '^([-0-9]+ [:0-9]+,[0-9]+) \[([-a-zA-Z0-9]+)\] \[([A-Z]+) *\] \(([.a-zA-Z0-9]+):([0-9]+)\) - (.*)$'
match = re.search(regex,line.encode('ascii'),flags = 0)
print Fore.MAGENTA + line
debug.append(match.group(6)[:40])
except Exception:
pass

print (Style.RESET_ALL)
warningdic = dict((x,warnings.count(x)) for x in set(warnings))
for key, value in sorted(warningdic.iteritems(), key=lambda (k,v): (v,k)):
print Fore.RED + "%s : times --- %s" % (key, value)

errorsdic = dict((x,errors.count(x)) for x in set(errors))
for key, value in sorted(errorsdic.iteritems(), key=lambda (k,v): (v,k)):
print Fore.YELLOW + "%s : times --- %s" % (key, value)

debugdic = dict((x,debug.count(x)) for x in set(debug))
for key,value in sorted(debugdic.iteritems(),key=lambda (k,v):(v,k)):
print Fore.MAGENTA + "%s : times --- %s" % (key,value)


print (Style.RESET_ALL)

readlogs()
exit()



40 changes: 32 additions & 8 deletions ArtifactoryLogParser/request.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
import sys
import re
import colorama
from colorama import Fore, Back, Style
#match.group(1) = time(example: 20160621065454)
#match.group(4) = IP Address
#match.group(6) = HTTP Method(GET,POST,PUT)
#match.group(7) = URL
#match.group(9) = HTTP Response Code

responsecodes = []


if len(sys.argv) !=2:
print('Usage: python request.py request.log')
sys.exit(0)

readfile = sys.argv[1]
with open(readfile) as f:
for line in f:
try:
p = re.compile(ur'(\d*)\|(\d*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)')
match = re.match(p,line)
print match.group(4) + " - " + match.group(6) + " - " + match.group(9)
except Exception:
pass

def readlogs():
with open(readfile) as f:
for line in f:
try:
p = re.compile(ur'(\d*)\|(\d*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)')
match = re.match(p,line)
response = match.group(4) + " - " + match.group(6) + " - " + match.group(9)
if match.group(9)[:1] == "2":
print Fore.GREEN + response
responsecodes.append(match.group(9))
elif match.group(9)[:1] == "4" or "5":
print Fore.RED + response
responsecodes.append(match.group(9))
else:
print response
responsecodes.append(match.group(9))
except Exception:
pass
print (Style.RESET_ALL)
responsedic = dict((x,responsecodes.count(x)) for x in set(responsecodes))
for key, value in sorted(responsedic.iteritems(), key=lambda (k,v): (v,k)):
print "%s: %s" % (key, value)


readlogs()
exit()
3 changes: 3 additions & 0 deletions BuildCleaner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Build Cleaner
Deletes any builds without a set status such as 'Staged' and 'Release'
Artifactory URL and credentials need to be set first, please use an 'Admin' user
44 changes: 44 additions & 0 deletions BuildCleaner/buildcleaner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import requests
import json
import sys
import re

username = "admin"
password = "password"
artifactory = "https://127.0.0.1:8081/artifactory/" # change this artifactory URL
#make sure to clarify if HTTP or HTTPS

def deletebuild(buildtodelete,idtodelete):
print buildtodelete + idtodelete
r = requests.delete(buildtodelete + idtodelete, auth= (username,password))

def inspectbuildjson(buildjson,buildjsonid):
#looks through every single build json in every build ID
r = requests.get(buildjson+buildjsonid, auth = (username, password))
buildinfo = json.loads(r.text)

if "statuses" not in buildinfo["buildInfo"] or len(buildinfo["buildInfo"]["statuses"]) == 0:
print "Deleting this build: " + buildjson + buildjsonid
deletebuild(buildjson,re.sub('/', '?buildNumbers=', buildjsonid))
else:
print "Keeping this build: " + buildjson + buildjsonid + " - " + buildinfo["buildInfo"]["statuses"][0]["status"]

def findbuildnumbers(buildname):
#finds all build ID's from all build projects
url = buildname
r = requests.get(url, auth = (username, password))
build_data = json.loads(r.text)
for item in build_data["buildsNumbers"]:
inspectbuildjson(url,item["uri"])

def getallbuilds():
#looks through all build projects
buildurl = "api/build"
url = artifactory + buildurl
r = requests.get(url, auth = (username, password))
json_data = json.loads(r.text)
for item in json_data["builds"]:
findbuildnumbers(url + item["uri"])


getallbuilds()
28 changes: 28 additions & 0 deletions REST-API-Examples/RestoreTrashCan.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "rubygems"
require "rest_client"
require "json"
#This script restores every file inside the Trashcan
user_name = 'admin' #change this
password= 'password' #change this
repo = "auto-trashcan"
artifactory = "http://127.0.0.1:8081/artifactory/api/storage/" #change this
listfolders = "?list&deep=1&listFolders=1"
url = artifactory + repo + listfolders
site = RestClient::Resource.new(url, user_name, password)
response = site.get(:accept=>"application/json")
string = response.body
parsed = JSON.parse(string)
parsed.map


while true
i = 0
trashedartifacts = parsed["files"][i]["uri"]
restoreurl = "http://127.0.0.1:8081/artifactory/api/trash/restore" + trashedartifacts + "?to=" + trashedartifacts #change my artifactory home
site2 = RestClient::Resource.new(restoreurl, user_name, password)
response2 = site2.post(:accept=>"application/json")
string2 = response2.body
puts string2
i+=1
end