Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaohe Cao
slapos
Commits
5ed0d5a6
Commit
5ed0d5a6
authored
Feb 25, 2016
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to configure multiple monitoring source
parent
defc6519
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
26 deletions
+57
-26
stack/monitor2/buildout.cfg
stack/monitor2/buildout.cfg
+3
-3
stack/monitor2/instance-monitor.cfg.jinja2.in
stack/monitor2/instance-monitor.cfg.jinja2.in
+6
-4
stack/monitor2/scripts/monitor.py
stack/monitor2/scripts/monitor.py
+14
-11
stack/monitor2/scripts/status2rss.py
stack/monitor2/scripts/status2rss.py
+34
-8
No files found.
stack/monitor2/buildout.cfg
View file @
5ed0d5a6
...
@@ -127,7 +127,7 @@ recipe = slapos.recipe.template:jinja2
...
@@ -127,7 +127,7 @@ recipe = slapos.recipe.template:jinja2
filename = template-monitor.cfg
filename = template-monitor.cfg
template = ${:_profile_base_location_}/instance-monitor.cfg.jinja2.in
template = ${:_profile_base_location_}/instance-monitor.cfg.jinja2.in
rendered = ${buildout:directory}/template-monitor.cfg
rendered = ${buildout:directory}/template-monitor.cfg
md5sum =
ee39ce85084d29172f50ae7375960371
md5sum =
b28523cd793788a1e1b11698c5a67b03
context =
context =
key apache_location apache:location
key apache_location apache:location
key gzip_location gzip:location
key gzip_location gzip:location
...
@@ -164,7 +164,7 @@ context =
...
@@ -164,7 +164,7 @@ context =
[monitor2-bin]
[monitor2-bin]
<= monitor-template-script
<= monitor-template-script
filename = monitor.py
filename = monitor.py
md5sum =
119827d7e7ed45c627f1ad21a94445b8
md5sum =
51ada466716af0a763910c24f1bdf819
[run-promise-py]
[run-promise-py]
recipe = slapos.recipe.template:jinja2
recipe = slapos.recipe.template:jinja2
...
@@ -183,7 +183,7 @@ md5sum = f7e937d6619eb674f39f34718928d91d
...
@@ -183,7 +183,7 @@ md5sum = f7e937d6619eb674f39f34718928d91d
[status2rss-executable]
[status2rss-executable]
<= monitor-template-script
<= monitor-template-script
filename = status2rss.py
filename = status2rss.py
md5sum =
40dcda69f1ccb8639d7ef0ad65bceb5e
md5sum =
f297779d0881f4bd48081506efb492a4
[monitor-globalstate]
[monitor-globalstate]
<= monitor-template-script
<= monitor-template-script
...
...
stack/monitor2/instance-monitor.cfg.jinja2.in
View file @
5ed0d5a6
...
@@ -133,6 +133,7 @@ public-folder = ${monitor-directory:public}
...
@@ -133,6 +133,7 @@ public-folder = ${monitor-directory:public}
private-folder = ${monitor-directory:private}
private-folder = ${monitor-directory:private}
webdav-folder = ${monitor-directory:webdav}
webdav-folder = ${monitor-directory:webdav}
web-folder = ${monitor-directory:web-dir}
web-folder = ${monitor-directory:web-dir}
#base-url = ${monitor-frontend-promise:url}
base-url = ${monitor-httpd-conf-parameter:url}
base-url = ${monitor-httpd-conf-parameter:url}
monitor-hal-json = ${monitor-directory:public}/monitor.hal.json
monitor-hal-json = ${monitor-directory:public}/monitor.hal.json
service-pid-folder = ${monitor-directory:pids}
service-pid-folder = ${monitor-directory:pids}
...
@@ -253,7 +254,9 @@ command = kill -USR1 $(cat ${monitor-httpd-conf-parameter:pid-file})
...
@@ -253,7 +254,9 @@ command = kill -USR1 $(cat ${monitor-httpd-conf-parameter:pid-file})
[monitor-status2rss-wrapper]
[monitor-status2rss-wrapper]
recipe = slapos.cookbook:wrapper
recipe = slapos.cookbook:wrapper
command-line = {{ python_with_eggs }} {{ status2rss_executable_path }} '${monitor-instance-parameter:monitor-title}' '${monitor-httpd-conf-parameter:url}' '${monitor-httpd-conf-parameter:url}/public' ${monitor-directory:public} ${monitor-directory:public}/feed
# XXX - hard-coded Urls
command-line = {{ python_with_eggs }} {{ status2rss_executable_path }} --output '${monitor-directory:public}/feed' --items_folder '${monitor-directory:public}' --public_url '${monitor-conf-parameters:base-url}/share/jio_public/' --private_url '${monitor-conf-parameters:base-url}/share/jio_private/' --instance_name '${monitor-conf-parameters:title}' --hosting_name '${monitor-conf-parameters:root-title}'
wrapper-path = ${directory:bin}/monitor-status2rss.py
wrapper-path = ${directory:bin}/monitor-status2rss.py
[monitor-status2rss-cron-entry]
[monitor-status2rss-cron-entry]
...
@@ -363,9 +366,8 @@ context =
...
@@ -363,9 +366,8 @@ context =
[publish]
[publish]
recipe = slapos.cookbook:publish
recipe = slapos.cookbook:publish
#monitor-base-url = ${monitor-httpd-conf-parameter:url}
monitor-base-url = ${monitor-conf-parameters:base-url}
monitor-base-url = ${monitor-frontend-promise:url}
monitor-url = ${:monitor-base-url}/public/feeds
monitor-url = ${:monitor-base-url}/share/jio_public
monitor-user = ${httpd-monitor-htpasswd:user}
monitor-user = ${httpd-monitor-htpasswd:user}
monitor-password = ${httpd-monitor-htpasswd:password}
monitor-password = ${httpd-monitor-htpasswd:password}
...
...
stack/monitor2/scripts/monitor.py
View file @
5ed0d5a6
...
@@ -15,7 +15,7 @@ OPML_START = """<?xml version="1.0" encoding="UTF-8"?>
...
@@ -15,7 +15,7 @@ OPML_START = """<?xml version="1.0" encoding="UTF-8"?>
<!-- OPML generated by SlapOS -->
<!-- OPML generated by SlapOS -->
<opml version="1.1">
<opml version="1.1">
<head>
<head>
<title>
SlapOS Monitoring Status List
s</title>
<title>
%(root_title)
s</title>
<dateCreated>%(creation_date)s</dateCreated>
<dateCreated>%(creation_date)s</dateCreated>
<dateModified>%(modification_date)s</dateModified>
<dateModified>%(modification_date)s</dateModified>
</head>
</head>
...
@@ -25,7 +25,7 @@ OPML_END = """ </outline>
...
@@ -25,7 +25,7 @@ OPML_END = """ </outline>
</body>
</body>
</opml>"""
</opml>"""
OPML_OUTLINE_FEED
=
'<outline text="%(title)s" title="%(title)s" type="rss" version="RSS" htmlUrl="%(html_url)s" xmlUrl="%(xml_url)s" />'
OPML_OUTLINE_FEED
=
'<outline text="%(title)s" title="%(title)s" type="rss" version="RSS" htmlUrl="%(html_url)s" xmlUrl="%(xml_url)s"
url="%(global_url)s"
/>'
def
parseArguments
():
def
parseArguments
():
...
@@ -172,8 +172,6 @@ class Monitoring(object):
...
@@ -172,8 +172,6 @@ class Monitoring(object):
raise
raise
def
generateOpmlFile
(
self
,
feed_url_list
,
output_file
):
def
generateOpmlFile
(
self
,
feed_url_list
,
output_file
):
if
not
feed_url_list
:
return
if
os
.
path
.
exists
(
output_file
):
if
os
.
path
.
exists
(
output_file
):
creation_date
=
datetime
.
fromtimestamp
(
os
.
path
.
getctime
(
output_file
)).
utcnow
().
strftime
(
"%a, %d %b %Y %H:%M:%S +0000"
)
creation_date
=
datetime
.
fromtimestamp
(
os
.
path
.
getctime
(
output_file
)).
utcnow
().
strftime
(
"%a, %d %b %Y %H:%M:%S +0000"
)
...
@@ -183,15 +181,18 @@ class Monitoring(object):
...
@@ -183,15 +181,18 @@ class Monitoring(object):
opml_content
=
OPML_START
%
{
'creation_date'
:
creation_date
,
opml_content
=
OPML_START
%
{
'creation_date'
:
creation_date
,
'modification_date'
:
modification_date
,
'modification_date'
:
modification_date
,
'outline_title'
:
'Monitoring RSS Feed list'
}
'outline_title'
:
'Monitoring RSS Feed list'
,
'root_title'
:
self
.
root_title
}
opml_content
+=
OPML_OUTLINE_FEED
%
{
'title'
:
'Main Instance'
,
opml_content
+=
OPML_OUTLINE_FEED
%
{
'title'
:
self
.
title
,
'html_url'
:
self
.
public_url
+
'/feed'
,
'html_url'
:
self
.
public_url
+
'/feed'
,
'xml_url'
:
self
.
public_url
+
'/feed'
}
'xml_url'
:
self
.
public_url
+
'/feed'
,
'global_url'
:
"%s/jio_public/"
%
self
.
webdav_url
}
for
feed_url
in
feed_url_list
:
for
feed_url
in
feed_url_list
:
opml_content
+=
OPML_OUTLINE_FEED
%
{
'title'
:
'Monitoring Instance'
,
opml_content
+=
OPML_OUTLINE_FEED
%
{
'title'
:
'
Related
Monitoring Instance'
,
'html_url'
:
feed_url
+
'/public/feed'
,
'html_url'
:
feed_url
+
'/public/feed'
,
'xml_url'
:
feed_url
+
'/public/feed'
}
'xml_url'
:
feed_url
+
'/public/feed'
,
'global_url'
:
"%s/share/jio_public/"
%
feed_url
}
opml_content
+=
OPML_END
opml_content
+=
OPML_END
...
@@ -223,8 +224,6 @@ class Monitoring(object):
...
@@ -223,8 +224,6 @@ class Monitoring(object):
if
self
.
monitor_url_list
:
if
self
.
monitor_url_list
:
monitor_link_dict
[
"related_monitor"
]
=
[{
"href"
:
url
}
monitor_link_dict
[
"related_monitor"
]
=
[{
"href"
:
url
}
for
url
in
self
.
monitor_url_list
]
for
url
in
self
.
monitor_url_list
]
self
.
generateOpmlFile
(
self
.
monitor_url_list
,
os
.
path
.
join
(
self
.
public_folder
,
'feeds'
))
self
.
monitor_dict
[
"_links"
]
=
monitor_link_dict
self
.
monitor_dict
[
"_links"
]
=
monitor_link_dict
if
self
.
promise_items
:
if
self
.
promise_items
:
service_list
=
[]
service_list
=
[]
...
@@ -324,6 +323,10 @@ class Monitoring(object):
...
@@ -324,6 +323,10 @@ class Monitoring(object):
self
.
monitor_dict
=
{}
self
.
monitor_dict
=
{}
self
.
generateMonitorHalJson
()
self
.
generateMonitorHalJson
()
# Generate OPML file
self
.
generateOpmlFile
(
self
.
monitor_url_list
,
os
.
path
.
join
(
self
.
public_folder
,
'feeds'
))
# put promises to a cron file
# put promises to a cron file
self
.
generateServiceCronEntries
()
self
.
generateServiceCronEntries
()
...
...
stack/monitor2/scripts/status2rss.py
View file @
5ed0d5a6
...
@@ -5,17 +5,40 @@ import datetime
...
@@ -5,17 +5,40 @@ import datetime
import
base64
import
base64
import
hashlib
import
hashlib
import
PyRSS2Gen
import
PyRSS2Gen
import
argparse
def
parseArguments
():
"""
Parse arguments for monitor Rss Generator.
"""
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--items_folder'
,
help
=
'Path where to get *.status.json files which contain result of promises.'
)
parser
.
add_argument
(
'--output'
,
help
=
'The Path of file where feed file will be saved.'
)
parser
.
add_argument
(
'--public_url'
,
help
=
'Monitor Instance public URL.'
)
parser
.
add_argument
(
'--private_url'
,
help
=
'Monitor Instance private URL.'
)
parser
.
add_argument
(
'--instance_name'
,
default
=
'UNKNOW Software Instance'
,
help
=
'Software Instance name.'
)
parser
.
add_argument
(
'--hosting_name'
,
default
=
''
,
help
=
'Hosting Subscription name.'
)
return
parser
.
parse_args
()
def
getKey
(
item
):
def
getKey
(
item
):
return
item
.
pubDate
return
item
.
pubDate
def
main
():
def
main
():
_
,
title
,
link
,
base_url
,
status_folder
,
output_path
=
sys
.
argv
parser
=
parseArguments
()
rss_item_list
=
[]
rss_item_list
=
[]
for
filename
in
os
.
listdir
(
statu
s_folder
):
for
filename
in
os
.
listdir
(
parser
.
item
s_folder
):
if
filename
.
endswith
(
".status.json"
):
if
filename
.
endswith
(
".status.json"
):
filepath
=
os
.
path
.
join
(
statu
s_folder
,
filename
)
filepath
=
os
.
path
.
join
(
parser
.
item
s_folder
,
filename
)
result_dict
=
None
result_dict
=
None
try
:
try
:
result_dict
=
json
.
load
(
open
(
filepath
,
"r"
))
result_dict
=
json
.
load
(
open
(
filepath
,
"r"
))
...
@@ -25,9 +48,12 @@ def main():
...
@@ -25,9 +48,12 @@ def main():
description
=
result_dict
.
get
(
'message'
,
''
)
description
=
result_dict
.
get
(
'message'
,
''
)
event_time
=
datetime
.
datetime
.
fromtimestamp
(
result_dict
[
'change-time'
])
event_time
=
datetime
.
datetime
.
fromtimestamp
(
result_dict
[
'change-time'
])
rss_item
=
PyRSS2Gen
.
RSSItem
(
rss_item
=
PyRSS2Gen
.
RSSItem
(
categories
=
[
result_dict
[
'status'
]],
source
=
PyRSS2Gen
.
Source
(
result_dict
[
'title'
],
parser
.
public_url
),
title
=
'[%s] %s'
%
(
result_dict
[
'status'
],
result_dict
[
'title'
]),
title
=
'[%s] %s'
%
(
result_dict
[
'status'
],
result_dict
[
'title'
]),
comments
=
description
,
description
=
"%s: %s
\
n
%s"
%
(
event_time
,
result_dict
[
'status'
],
description
),
description
=
"%s: %s
\
n
%s"
%
(
event_time
,
result_dict
[
'status'
],
description
),
link
=
'%s/%s'
%
(
base_url
,
filename
)
,
link
=
parser
.
private_url
,
pubDate
=
event_time
,
pubDate
=
event_time
,
guid
=
PyRSS2Gen
.
Guid
(
base64
.
b64encode
(
"%s, %s"
%
(
event_time
,
result_dict
[
'status'
])))
guid
=
PyRSS2Gen
.
Guid
(
base64
.
b64encode
(
"%s, %s"
%
(
event_time
,
result_dict
[
'status'
])))
)
)
...
@@ -37,13 +63,13 @@ def main():
...
@@ -37,13 +63,13 @@ def main():
### Build the rss feed
### Build the rss feed
sorted
(
rss_item_list
,
key
=
getKey
)
sorted
(
rss_item_list
,
key
=
getKey
)
rss_feed
=
PyRSS2Gen
.
RSS2
(
rss_feed
=
PyRSS2Gen
.
RSS2
(
title
=
titl
e
,
title
=
parser
.
instance_nam
e
,
link
=
link
,
link
=
parser
.
public_url
,
description
=
''
,
description
=
parser
.
hosting_name
,
lastBuildDate
=
datetime
.
datetime
.
utcnow
(),
lastBuildDate
=
datetime
.
datetime
.
utcnow
(),
items
=
rss_item_list
items
=
rss_item_list
)
)
with
open
(
output_path
,
'w'
)
as
frss
:
with
open
(
parser
.
output
,
'w'
)
as
frss
:
frss
.
write
(
rss_feed
.
to_xml
())
frss
.
write
(
rss_feed
.
to_xml
())
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
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