1
+ '''
2
+ Created on April 26, 2023
3
+ @author: kumykov
4
+
5
+ Copyright (C) 2023 Synopsys, Inc.
6
+ http://www.blackducksoftware.com/
7
+
8
+ Licensed to the Apache Software Foundation (ASF) under one
9
+ or more contributor license agreements. See the NOTICE file
10
+ distributed with this work for additional information
11
+ regarding copyright ownership. The ASF licenses this file
12
+ to you under the Apache License, Version 2.0 (the
13
+ "License"); you may not use this file except in compliance
14
+ with the License. You may obtain a copy of the License at
15
+
16
+ http://www.apache.org/licenses/LICENSE-2.0
17
+
18
+ Unless required by applicable law or agreed to in writing,
19
+ software distributed under the License is distributed on an
20
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ KIND, either express or implied. See the License for the
22
+ specific language governing permissions and limitations
23
+ under the License.
24
+
25
+ This script will read the content of the job page from diagnostic section
26
+ in Blackduck.
27
+
28
+ Data will be written into a file named bd-stats-<isotamestamp>.txt
29
+
30
+ Requirements
31
+
32
+ - python3 version 3.8 or newer recommended
33
+ - the following packages are used by the script and should be installed
34
+ prior to use:
35
+ argparse
36
+ blackduck
37
+ logging
38
+ datetime
39
+
40
+ - Blackduck instance
41
+ - API token with sufficient privileges to perform project version phase
42
+ change.
43
+
44
+ Install python packages with the following command:
45
+
46
+ pip3 install argparse blackduck logging datetime
47
+
48
+ Using
49
+
50
+ place the token into a file (token in this example) then execute:
51
+
52
+ python3 get_debug_page.py -u $BD_URL -t token -nv
53
+
54
+
55
+ usage: python3 get_debug_page.py [-h] -u BASE_URL -t TOKEN_FILE [-nv] [-o OUTPUT_FILE] [--stdout]
56
+
57
+ options:
58
+ -h, --help show this help message and exit
59
+ -u BASE_URL, --base-url BASE_URL
60
+ Hub server URL e.g. https://your.blackduck.url
61
+ -t TOKEN_FILE, --token-file TOKEN_FILE
62
+ containing access token
63
+ -nv, --no-verify disable TLS certificate verification
64
+ -o OUTPUT_FILE, --output-file OUTPUT_FILE
65
+ Output file name pattern
66
+ --stdout Output to stdout, instead of the file
67
+
68
+ '''
69
+
70
+ from blackduck import Client
71
+
72
+ import argparse
73
+ import logging
74
+ from pprint import pprint
75
+ from datetime import datetime
76
+
77
+ logging .basicConfig (
78
+ level = logging .DEBUG ,
79
+ format = "[%(asctime)s] {%(module)s:%(lineno)d} %(levelname)s - %(message)s"
80
+ )
81
+
82
+ parser = argparse .ArgumentParser ("Get a job stats from debug page" )
83
+ parser .add_argument ("-u" , "--base-url" , required = True , help = "Hub server URL e.g. https://your.blackduck.url" )
84
+ parser .add_argument ("-t" , "--token-file" , dest = 'token_file' , required = True , help = "containing access token" )
85
+ parser .add_argument ("-nv" , "--no-verify" , dest = 'verify' , action = 'store_false' , help = "disable TLS certificate verification" )
86
+ parser .add_argument ("-o" , "--output-file" , dest = 'output_file' , default = 'bd-stats' , help = "Output file name pattern" )
87
+ parser .add_argument ("--stdout" , dest = 'stdout' , action = 'store_true' , help = 'Output to stdout, instead of the file' )
88
+ args = parser .parse_args ()
89
+
90
+ with open (args .token_file , 'r' ) as tf :
91
+ access_token = tf .readline ().strip ()
92
+
93
+ bd = Client (base_url = args .base_url , token = access_token , verify = args .verify )
94
+
95
+ url = "https://ec2-44-202-86-163.compute-1.amazonaws.com/debug?job=true"
96
+
97
+ result = bd .session .get (url )
98
+
99
+ if args .stdout :
100
+ print (result .text )
101
+
102
+ else :
103
+ timestamp = datetime .now ().isoformat ()
104
+ filename = f"{ args .output_file } -{ timestamp } .txt"
105
+ f = open (filename ,"w" )
106
+ f .write (result .text )
107
+ f .close ()
0 commit comments