Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Tyagov
slapos.package
Commits
b443828c
Commit
b443828c
authored
Sep 17, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
netdrive: use json not eval, fixed XML report, --verbose
parent
487a225a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
windows/netreport/netreport.py
windows/netreport/netreport.py
+14
-8
windows/service/slapos-monitor
windows/service/slapos-monitor
+2
-1
No files found.
windows/netreport/netreport.py
View file @
b443828c
...
...
@@ -27,10 +27,10 @@
#
##############################################################################
import
argparse
import
json
import
os.path
import
slapos.slap.slap
import
sqlite3
import
sys
import
xmlrpclib
from
datetime
import
datetime
,
date
...
...
@@ -67,6 +67,7 @@ def parseArgumentTuple():
help
=
"If True, send report per day at mid-night. "
"Otherwise send report instantly."
,
default
=
False
)
parser
.
add_argument
(
'--verbose'
,
action
=
'store_true'
)
option
=
parser
.
parse_args
()
# Build option_dict
...
...
@@ -129,6 +130,9 @@ class NetDriveUsageReporter(object):
current_timestamp
=
datetime
.
now
()
d
=
current_timestamp
-
last_timestamp
if
d
.
seconds
<
self
.
report_interval
:
if
self
.
verbose
:
print
'sleeping'
,
interval
print
'%s < %s'
%
(
d
.
seconds
,
self
.
report_interval
)
sleep
(
interval
)
continue
self
.
insertUsageReport
(
monitor
,
last_timestamp
.
isoformat
(),
d
.
seconds
)
...
...
@@ -141,7 +145,7 @@ class NetDriveUsageReporter(object):
def
insertUsageReport
(
self
,
monitor
,
start
,
duration
):
q
=
self
.
_db
.
execute
for
r
in
eval
(
monitor
.
netdrive_usage
()):
for
r
in
json
.
loads
(
monitor
.
netdrive_usage
()):
q
(
"INSERT INTO net_drive_usage "
"(config_id, domain_user, drive_letter, remote_folder, "
" start, duration, usage_bytes )"
...
...
@@ -167,6 +171,8 @@ class NetDriveUsageReporter(object):
# (Optional) Move all the reported data to histroy table
today
=
date
.
today
().
isoformat
()
if
(
not
self
.
batch
)
or
self
.
_report_date
<
today
:
if
self
.
verbose
:
print
'Creating report'
self
.
_postData
(
self
.
generateDailyReport
(
self
.
_config_id
,
self
.
computer_id
,
self
.
_report_date
))
...
...
@@ -221,7 +227,7 @@ class NetDriveUsageReporter(object):
movement
=
etree
.
Element
(
'movement'
)
element
=
etree
.
Element
(
"resource"
)
element
.
text
=
r
[
0
]
element
.
text
=
r
[
1
]
movement
.
append
(
element
)
element
=
etree
.
Element
(
"title"
)
...
...
@@ -229,15 +235,15 @@ class NetDriveUsageReporter(object):
movement
.
append
(
element
)
element
=
etree
.
Element
(
"reference"
)
element
.
text
=
etree
.
Element
(
"domain_user"
),
element
.
text
=
r
[
0
]
movement
.
append
(
element
)
element
=
etree
.
Element
(
"reference"
)
element
.
text
=
report_date
movement
.
append
(
element
)
#
element = etree.Element("reference")
#
element.text = report_date
#
movement.append(element)
element
=
etree
.
Element
(
"quantity"
)
element
.
text
=
str
(
r
[
1
]
*
r
[
2
])
element
.
text
=
str
(
r
[
2
]
*
r
[
3
])
movement
.
append
(
element
)
element
=
etree
.
Element
(
"price"
)
...
...
windows/service/slapos-monitor
View file @
b443828c
#!/usr/bin/python
import
json
import
logging
import
os
import
sys
...
...
@@ -33,7 +34,7 @@ class SlapNodeMonitor(object):
for
k
in
self
.
drivelist
:
r
=
netuse
.
usageReport
(
k
[
0
])
result
.
append
((
k
[
3
],
k
[
0
],
k
[
1
],
r
[
0
],
r
[
1
]))
return
repr
(
result
)
return
json
.
dumps
(
result
)
def
run
(
self
):
# Create server
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment