Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-report
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tools
gitlab-report
Commits
d26b2807
Commit
d26b2807
authored
1 year ago
by
Sigmund, Dominik
Browse files
Options
Downloads
Patches
Plain Diff
Update file script.py
parent
8944df6d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
script.py
+36
-14
36 additions, 14 deletions
script.py
with
36 additions
and
14 deletions
script.py
+
36
−
14
View file @
d26b2807
...
...
@@ -42,21 +42,31 @@ def load_api_token():
def
get_disk_space
():
# Run the df command to get disk space information
result
=
subprocess
.
run
([
'
df
'
,
'
-h
'
],
capture_output
=
True
,
text
=
True
)
result
=
subprocess
.
run
([
'
df
'
,
'
-h
'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
universal_newlines
=
True
)
# Extract the output and parse the relevant information
output_lines
=
result
.
stdout
.
strip
().
split
(
'
\n
'
)
header_line
,
*
data_lines
=
output_lines
# Find the line containing '/data'
data_line
=
None
for
line
in
output_lines
:
if
'
/data
'
in
line
:
data_line
=
line
break
if
data_line
is
None
:
print
(
"
Error: /data not found in the
'
df
'
output.
"
)
return
None
data_info
=
data_line
.
split
()
# Assuming the output format of 'df -h' is as follows:
# Filesystem Size Used Avail Use% Mounted on
# /dev/sda1 100G 50G 50G 50% /
# ...
# Extracting the available space (Avail) from the first line of data
disk_space_info
=
header_line
.
split
()
free_space_on_disk
=
disk_space_info
[
3
]
# Extract the available space (Avail) and percentage (Use%) for /data
free_space_on_data
=
data_info
[
3
]
data_percentage
=
data_info
[
4
]
return
free_space_on_d
isk
return
f
"
{
free_space_on_d
ata
}
(
{
data_percentage
}
%)
"
def
get_total_commits_last_month
(
gl
):
# Calculate the date range for the last month
...
...
@@ -88,7 +98,7 @@ def get_projects_with_no_activity(gl):
def
get_gitlab_version
():
# Run 'gitlab-ctl' command to get GitLab version
result
=
subprocess
.
run
([
'
gitlab-
ctl
'
,
'
version
'
],
capture_output
=
True
,
text
=
True
)
result
=
subprocess
.
run
([
'
grep
'
,
'
gitlab-
ee
'
,
'
/opt/gitlab/version-manifest.txt
'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
universal_newlines
=
True
)
# Extract GitLab version from the output
gitlab_version
=
result
.
stdout
.
strip
()
...
...
@@ -97,33 +107,45 @@ def get_gitlab_version():
def
get_gitlab_info
(
api_token
):
# Replace 'YOUR_GITLAB_URL' and 'YOUR_PRIVATE_TOKEN' with your GitLab URL and private token
print
(
"
Auth against
"
+
gitlab_url
)
gl
=
gitlab
.
Gitlab
(
gitlab_url
,
api_token
)
gl
.
auth
()
print
(
"
Auth successful
"
)
# Get the number of projects
projects
=
gl
.
projects
.
list
()
num_projects
=
len
(
projects
)
print
(
f
"
Number of projects:
{
num_projects
}
"
)
# Get the number of users
users
=
gl
.
users
.
list
(
all
=
True
)
num_users
=
len
(
users
)
print
(
f
"
Number of users:
{
num_users
}
"
)
# Get a list of admin users
admin_users
=
[
user
for
user
in
users
if
user
.
is_admin
]
admin_users
=
[
user
for
user
in
users
if
hasattr
(
user
,
'
is_admin
'
)
and
user
.
is_admin
]
admin_users_list
=
[
user
.
name
for
user
in
admin_users
]
print
(
f
"
Number of Admin-Users:
{
len
(
admin_users_list
)
}
"
)
# Get free space on disk
free_space_on_disk
=
get_disk_space
()
print
(
f
"
Free space on disk:
{
free_space_on_disk
}
"
)
# Get the total commits last month
total_commits_last_month
=
get_total_commits_last_month
(
gl
)
print
(
f
"
Total commits last month:
{
total_commits_last_month
}
"
)
# Get projects with no activity
projects_with_no_activity
=
get_projects_with_no_activity
(
gl
)
print
(
f
"
Projects with no activity:
{
len
(
projects_with_no_activity
)
}
"
)
# Get GitLab version
gitlab_version
=
get_gitlab_version
()
print
(
f
"
GitLab version:
{
gitlab_version
}
"
)
return
num_projects
,
num_users
,
admin_users_list
,
free_space_on_disk
,
total_commits_last_month
,
projects_with_no_activity
,
gitlab_version
...
...
@@ -222,7 +244,7 @@ api_token, confluence_token = load_api_token()
subject
=
'
Monthly GitLab Report - {month} {year}
'
.
format
(
month
=
datetime
.
datetime
.
now
().
strftime
(
'
%B
'
),
year
=
datetime
.
datetime
.
now
().
strftime
(
'
%Y
'
))
# Get GitLab information
num_projects
,
num_users
,
admin_users_list
,
free_space_on_disk
=
get_gitlab_info
(
api_token
)
num_projects
,
num_users
,
admin_users_list
,
free_space_on_disk
,
total_commits_last_month
,
projects_with_no_activity
,
gitlab_version
=
get_gitlab_info
(
api_token
)
# Compose the email body as a dictionary
email_body
=
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment