Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Picametrics
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
Container Registry
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Picasoft
Technique
Picametrics
Commits
8eb327f3
Unverified
Commit
8eb327f3
authored
4 years ago
by
PICHOU Kyâne
Browse files
Options
Downloads
Patches
Plain Diff
Comment Wekan private boards part
parent
8c735c1f
No related branches found
Branches containing commit
Tags
v1.1
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
wekan/wekan.py
+35
-33
35 additions, 33 deletions
wekan/wekan.py
with
36 additions
and
34 deletions
README.md
+
1
−
1
View file @
8eb327f3
...
...
@@ -114,7 +114,7 @@ Mattermost module exports following metrics :
-
`wekan_total_users`
: Number of users on the instance
-
`wekan_public_boards`
: Number of public boards on the instance
-
`wekan_private_boards`
: Number of private channels on the instance
<!--
- `wekan_private_boards` : Number of private channels on the instance
-->
Each metric have a
`name`
tag with the name of the instance.
...
...
This diff is collapsed.
Click to expand it.
wekan/wekan.py
+
35
−
33
View file @
8eb327f3
...
...
@@ -8,6 +8,7 @@ import requests
from
urllib.parse
import
urlparse
import
sys
class
WekanCollector
():
"""
WekanCollector.
...
...
@@ -67,16 +68,16 @@ class WekanCollector():
'
value
'
:
data
[
'
publicBoards
'
]
}
})
metrics
.
append
({
'
measurement
'
:
'
wekan_private_boards
'
,
'
tags
'
:
{
'
name
'
:
instance
[
'
name
'
]
},
'
time
'
:
current_timestamp
,
'
fields
'
:
{
'
value
'
:
data
[
'
privateBoards
'
]
}
})
#
metrics.append({
#
'measurement': 'wekan_private_boards',
#
'tags': {
#
'name': instance['name']
#
},
#
'time': current_timestamp,
#
'fields': {
#
'value': data['privateBoards']
#
}
#
})
print
(
"
Wekan : data collected for instance {}
"
.
format
(
instance
[
'
name
'
]))
return
metrics
...
...
@@ -89,10 +90,10 @@ class WekanCollector():
:returns: Authentication token
"""
login
=
requests
.
post
(
instance
[
'
url
'
]
+
'
/users/login
'
,
data
=
{
"
username
"
:
instance
[
'
user
'
],
"
password
"
:
instance
[
'
password
'
]
})
data
=
{
"
username
"
:
instance
[
'
user
'
],
"
password
"
:
instance
[
'
password
'
]
})
if
login
.
status_code
!=
200
:
print
(
'
Unable to login to {} instance : {}
'
.
format
(
instance
[
'
url
'
],
login
.
reason
))
...
...
@@ -127,24 +128,25 @@ class WekanCollector():
else
:
data
[
'
publicBoards
'
]
=
len
(
public_boards
)
# API does not have a method to get all boards, so first get
# boards for each users
all_boards
=
[]
for
user
in
users
:
boards
=
requests
.
get
(
instance
[
'
url
'
]
+
f
'
/api/users/
{
user
[
"
_id
"
]
}
/boards
'
,
headers
=
headers
).
json
()
if
isinstance
(
public_boards
,
dict
)
and
public_boards
.
get
(
'
statusCode
'
,
200
)
!=
200
:
print
(
'
Unable to get public boards from {} instance : {}
'
.
format
(
instance
[
'
url
'
],
public_boards
[
'
reason
'
]))
else
:
# Then remove default boards (we don't care)
for
e
in
boards
:
if
e
[
'
title
'
]
==
'
Welcome Board
'
or
e
[
'
title
'
]
==
'
Templates
'
:
boards
.
remove
(
e
)
all_boards
.
extend
(
boards
)
# Finally filter unique boards
all_boards_unique
=
list
({
v
[
'
_id
'
]:
v
for
v
in
all_boards
}.
values
())
# Then infer number of private boards from total boards - public boards
data
[
'
privateBoards
'
]
=
len
(
all_boards_unique
)
-
len
(
public_boards
)
# TODO This part takes a lot of times (about 8 minutes) to process. We should find another way to do this
# # API does not have a method to get all boards, so first get
# # boards for each users
# all_boards = []
# for user in users:
# boards = requests.get(instance['url'] + f'/api/users/{user["_id"]}/boards', headers=headers).json()
# if isinstance(public_boards, dict) and public_boards.get('statusCode', 200) != 200:
# print('Unable to get public boards from {} instance : {}'.format(instance['url'], public_boards['reason']))
# else:
# # Then remove default boards (we don't care)
# for e in boards:
# if e['title'] == 'Welcome Board' or e['title'] == 'Templates':
# boards.remove(e)
# all_boards.extend(boards)
# # Finally filter unique boards
# all_boards_unique = list({v['_id']: v for v in all_boards}.values())
# # Then infer number of private boards from total boards - public boards
# data['privateBoards'] = len(all_boards_unique) - len(public_boards)
return
data
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