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
Arnaud Véron
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 @@
...
@@ -27,10 +27,10 @@
#
#
##############################################################################
##############################################################################
import
argparse
import
argparse
import
json
import
os.path
import
os.path
import
slapos.slap.slap
import
slapos.slap.slap
import
sqlite3
import
sqlite3
import
sys
import
xmlrpclib
import
xmlrpclib
from
datetime
import
datetime
,
date
from
datetime
import
datetime
,
date
...
@@ -67,6 +67,7 @@ def parseArgumentTuple():
...
@@ -67,6 +67,7 @@ def parseArgumentTuple():
help
=
"If True, send report per day at mid-night. "
help
=
"If True, send report per day at mid-night. "
"Otherwise send report instantly."
,
"Otherwise send report instantly."
,
default
=
False
)
default
=
False
)
parser
.
add_argument
(
'--verbose'
,
action
=
'store_true'
)
option
=
parser
.
parse_args
()
option
=
parser
.
parse_args
()
# Build option_dict
# Build option_dict
...
@@ -129,6 +130,9 @@ class NetDriveUsageReporter(object):
...
@@ -129,6 +130,9 @@ class NetDriveUsageReporter(object):
current_timestamp
=
datetime
.
now
()
current_timestamp
=
datetime
.
now
()
d
=
current_timestamp
-
last_timestamp
d
=
current_timestamp
-
last_timestamp
if
d
.
seconds
<
self
.
report_interval
:
if
d
.
seconds
<
self
.
report_interval
:
if
self
.
verbose
:
print
'sleeping'
,
interval
print
'%s < %s'
%
(
d
.
seconds
,
self
.
report_interval
)
sleep
(
interval
)
sleep
(
interval
)
continue
continue
self
.
insertUsageReport
(
monitor
,
last_timestamp
.
isoformat
(),
d
.
seconds
)
self
.
insertUsageReport
(
monitor
,
last_timestamp
.
isoformat
(),
d
.
seconds
)
...
@@ -141,7 +145,7 @@ class NetDriveUsageReporter(object):
...
@@ -141,7 +145,7 @@ class NetDriveUsageReporter(object):
def
insertUsageReport
(
self
,
monitor
,
start
,
duration
):
def
insertUsageReport
(
self
,
monitor
,
start
,
duration
):
q
=
self
.
_db
.
execute
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 "
q
(
"INSERT INTO net_drive_usage "
"(config_id, domain_user, drive_letter, remote_folder, "
"(config_id, domain_user, drive_letter, remote_folder, "
" start, duration, usage_bytes )"
" start, duration, usage_bytes )"
...
@@ -167,6 +171,8 @@ class NetDriveUsageReporter(object):
...
@@ -167,6 +171,8 @@ class NetDriveUsageReporter(object):
# (Optional) Move all the reported data to histroy table
# (Optional) Move all the reported data to histroy table
today
=
date
.
today
().
isoformat
()
today
=
date
.
today
().
isoformat
()
if
(
not
self
.
batch
)
or
self
.
_report_date
<
today
:
if
(
not
self
.
batch
)
or
self
.
_report_date
<
today
:
if
self
.
verbose
:
print
'Creating report'
self
.
_postData
(
self
.
generateDailyReport
(
self
.
_config_id
,
self
.
_postData
(
self
.
generateDailyReport
(
self
.
_config_id
,
self
.
computer_id
,
self
.
computer_id
,
self
.
_report_date
))
self
.
_report_date
))
...
@@ -221,7 +227,7 @@ class NetDriveUsageReporter(object):
...
@@ -221,7 +227,7 @@ class NetDriveUsageReporter(object):
movement
=
etree
.
Element
(
'movement'
)
movement
=
etree
.
Element
(
'movement'
)
element
=
etree
.
Element
(
"resource"
)
element
=
etree
.
Element
(
"resource"
)
element
.
text
=
r
[
0
]
element
.
text
=
r
[
1
]
movement
.
append
(
element
)
movement
.
append
(
element
)
element
=
etree
.
Element
(
"title"
)
element
=
etree
.
Element
(
"title"
)
...
@@ -229,15 +235,15 @@ class NetDriveUsageReporter(object):
...
@@ -229,15 +235,15 @@ class NetDriveUsageReporter(object):
movement
.
append
(
element
)
movement
.
append
(
element
)
element
=
etree
.
Element
(
"reference"
)
element
=
etree
.
Element
(
"reference"
)
element
.
text
=
etree
.
Element
(
"domain_user"
),
element
.
text
=
r
[
0
]
movement
.
append
(
element
)
movement
.
append
(
element
)
element
=
etree
.
Element
(
"reference"
)
#
element = etree.Element("reference")
element
.
text
=
report_date
#
element.text = report_date
movement
.
append
(
element
)
#
movement.append(element)
element
=
etree
.
Element
(
"quantity"
)
element
=
etree
.
Element
(
"quantity"
)
element
.
text
=
str
(
r
[
1
]
*
r
[
2
])
element
.
text
=
str
(
r
[
2
]
*
r
[
3
])
movement
.
append
(
element
)
movement
.
append
(
element
)
element
=
etree
.
Element
(
"price"
)
element
=
etree
.
Element
(
"price"
)
...
...
windows/service/slapos-monitor
View file @
b443828c
#!/usr/bin/python
#!/usr/bin/python
import
json
import
logging
import
logging
import
os
import
os
import
sys
import
sys
...
@@ -33,7 +34,7 @@ class SlapNodeMonitor(object):
...
@@ -33,7 +34,7 @@ class SlapNodeMonitor(object):
for
k
in
self
.
drivelist
:
for
k
in
self
.
drivelist
:
r
=
netuse
.
usageReport
(
k
[
0
])
r
=
netuse
.
usageReport
(
k
[
0
])
result
.
append
((
k
[
3
],
k
[
0
],
k
[
1
],
r
[
0
],
r
[
1
]))
result
.
append
((
k
[
3
],
k
[
0
],
k
[
1
],
r
[
0
],
r
[
1
]))
return
repr
(
result
)
return
json
.
dumps
(
result
)
def
run
(
self
):
def
run
(
self
):
# Create server
# 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