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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ tramp

# Pycharm
.idea
virtualenv_3_7/include/
7 changes: 0 additions & 7 deletions AQL-Examples/artifacts-created-earlier-than.json

This file was deleted.

2 changes: 0 additions & 2 deletions AQL-Examples/artifacts-modified-within-last.json

This file was deleted.

1 change: 0 additions & 1 deletion AQL-Examples/artifacts-with-property.json

This file was deleted.

34 changes: 34 additions & 0 deletions AQL-Examples/cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import requests

def deep_clean():

base_url = 'http://localhost:8081/artifactory/'
base_name_to_search = "Test-SNAPSHOT-*.ear"

headers = {'content-type': 'text/plain'}
data = 'items.find({"name":{"$match":"%s"}})' % base_name_to_search
limit_number = 4
response = requests.post(base_url+'api/search/aql', auth=('admin', 'NewPassword'), headers=headers, data=data)


for result in eval(response.text)["results"]:

name = result['name']
path = result['path'] + '/'
repo = result['repo']
if path == './':
path = ''

full_path = repo + '/' + path + name

artifact_url = base_url + full_path
version = name.split('-')[-1].split('.')[0]

if int(version) < limit_number:
print(full_path)
print(artifact_url)
requests.delete(artifact_url, auth=('admin', 'NewPassword'))

if __name__ == '__main__':
deep_clean()

28 changes: 24 additions & 4 deletions ArtifactoryLogParser/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
# Artifactory Log Parser
Uses regex to parse Artifactory logs
A script that allows to parse Artifactory logs and output them in a
readable and organized way.


## Installation and Configuration
No external dependencies are necessary. <p>
Code has been tested and optimized for Pyhton 2.7 or Python 3.6 running
on Unix systems. Coloring might not work on Windows machines.


## Usage
To run the script you must simply pass the file path along with options
and search filters. The filters\options available are the following: <p>
`WARN`, `ERROR`, `INFO`, `nocolor` <p>


Example commands:

python artifactory.py $artifactory.log
python access.py $access.log
python request.py $request.log
`python artifactory.py /path/to/artifactory.log WARN` <p>
`python artifactory.py /path/to/artifactory.log ERROR WARN` <p>
`python artifactory.py /path/to/artifactory.log ERROR nocolor` <p>

Under construction (only functional with Python 2.7.
No advanced options):

`python access.py /path/to/access.log` <p>
`python request.py /path/to/request.log` <p>
147 changes: 100 additions & 47 deletions ArtifactoryLogParser/artifactory.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,103 @@
#!/usr/bin/python
import re
import sys
import colorama
from colorama import Fore, Back, Style

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


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:
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))

except Exception:
pass

print (Style.RESET_ALL)
exit()




class Colors:

def __init__(self):
self.HEADER = '\033[95m'
self.OKBLUE = '\033[94m'
self.OKGREEN = '\033[92m'
self.WARNING = '\033[93m'
self.FAIL = '\033[91m'
self.ENDC = '\033[0m'

def disable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''

def clear(self):
print(self.ENDC)


class Logger:

default_sf = ["WARN", "ERROR", "INFO"]

def __init__(self, readfile, regex):
self.colors = Colors()
self.data = {
'WARN':
{'results': [],
'color': self.colors.WARNING,
'message': 'WARNING:'},
'ERROR':
{'results': [],
'color': self.colors.FAIL,
'message': 'ERROR:'},
'INFO':
{'results': [],
'color': self.colors.OKBLUE,
'message': 'INFO:'
}
}
self.readfile = readfile
self.regex = regex

def parse(self):
with open(self.readfile) as f:
for line in f.readlines():
match = re.search(self.regex, line, flags=0)
if match:
e_type = [x for x in self.default_sf if x in line][0]
entry = ' '.join([self.data[e_type]['color'], self.data[e_type]['message'], (match.group(6))])
self.data[e_type]['results'].append(entry)

def output(self, sf):
for entry_type in self.data:
if entry_type in sf:
for result in self.data[entry_type]["results"]:
print(result)

def disable_color(self):
for entry_type in self.data:
self.data[entry_type]["color"] = ''


def main():

# Gather input values
readfile = sys.argv[1]
regex = '^([-0-9]+ [:0-9]+,[0-9]+) \[([-a-zA-Z0-9]+)\] \[([A-Z]+) *\] \(([.a-zA-Z0-9]+):([0-9]+)\) - (.*)$'
logger = Logger(readfile, regex)
n_args = len(sys.argv)

if n_args < 2:
print('Usage: python artifactory.py /path/to/artifactory.log [filters]')
sys.exit(0)

elif n_args == 2:
search_filter = logger.default_sf
else:
search_filter = sys.argv[2:]

if "nocolor" in search_filter:
logger.disable_color()

logger.parse()
logger.output(sf=search_filter)
logger.colors.clear()
exit()


if __name__ == '__main__':
main()





6 changes: 3 additions & 3 deletions ArtifactoryLogParser/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
with open(readfile) as f:
for line in f:
try:
p = re.compile(ur'(\d*)\|(\d*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)')
p = re.compile(r'(\d*)\|(\d*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)')
match = re.match(p,line)
print match.group(4) + " - " + match.group(6) + " - " + match.group(9)
print(match.group(4) + " - " + match.group(6) + " - " + match.group(9))
except Exception:
pass
exit()
exit()
2 changes: 1 addition & 1 deletion DownloadUsage/DownloadUsage.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
print Fore.RED + "Could not find",(notfound),"artifacts(most likely deleted)"
print Fore.GREEN + "Total download usage:",(totalbytes/1000000),"MB"
print (Style.RESET_ALL)
exit()
exit()
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
username = "admin"
password = "password"
artifactory = "http://127.0.0.1:8081/artifactory/" #artifactory URL
api = "api/security/users/admin" #you can change this API URL to any API method you'd like to use
api = "api/security/users/admin" # you can change this API URL to any API method you'd like to use

url = artifactory + api
r = requests.get(url, auth = (username, password)) #this script is only for API methods that use GET

if r.status_code == 200:
print r.content
print(r.content)
else:
print "Fail"
print("Fail")
response = json.loads(r.content)
print response["errors"]
print(response["errors"])

print "x-request-id : " + r.headers['x-request-id']
print "Status Code : " + r.status_code
print("x-request-id : " + r.headers['x-request-id'])
print("Status Code : " + r.status_code)
37 changes: 37 additions & 0 deletions REST-API-Examples/PythonRestClient/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
artifactopy - Artiactory's Python REST Client
=============================================

Artifactopy allows for quick use of the Artifactory REST API for the automation
of get, put, post, delete, and patch operations.

The library has been tested on and is compatible with Python 3.6 and above.

Structure
---------

The library has a structure that reflects each operation's usage and request type.
- `artifactopy.api`: (All API requests as classes)
- `artifactopy.api.get`: (all GET requests)
- `artifactopy.api.put`: (all PUT requests)
- `artifactopy.api.post`: (all POST requests)
- `artifactopy.api.patch`: (all PATCH requests)
- `artifactopy.api.delete`: (all DELETE requests)
- `artifactopy.auth`: (Authentication classes)
- `artifactopy.models`: (JSON classes)

Examples
--------------------------------------------------------------------------------------

`test test`

*The -download_missingfiles flag can take `yes or no` as a value and when you pass `yes` the script will download all the files that are present in Source repository and missing from the Target repository to a folder 'replication_downloads' in the current working directory*

**If you don't want to provide parameters for the script, then you could just run the script without any of the above options and it will prompt you for all the details of the source Artifactory instance and target Artifactory instance.**

**NOTE:**
----------
*After a successful run of the script it will provide you with the count of files sorted according to the file extension that are present in the source repository and are missing in the target repository.*

*In the current working directory you will find a text file named **"filepaths_uri.txt"** which contains all the artifacts including metadata files that are present in the source repository and missing in the target repository. It will include the entire URL of the source Artifactory and the path to the artifact.*

*You will also find another text file named **"filepaths_nometadatafiles.txt"** which contains only the artifacts and not metadata files that are present in the source repository and missing in the target repository. Since metadata files are not necessary as the target repository is responsible for calculating metadata, we have filtered them to only provide the missing artifacts.*
Empty file.
13 changes: 13 additions & 0 deletions REST-API-Examples/PythonRestClient/artifactopy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Add the b directory to your sys.path

import sys, os
parent_dir = os.getcwd() # find the path to module a
# Then go up one level to the common parent directory
path = os.path.dirname(parent_dir)
# Add the parent to sys.pah
sys.path.append(parent_dir)

# Now you can import anything from b.s
import api

print(api.get)
Binary file not shown.
Loading