File: test.py

package info (click to toggle)
shinken-mod-webui 1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 14,136 kB
  • ctags: 2,980
  • sloc: python: 3,654; sh: 47; makefile: 19; sql: 3
file content (36 lines) | stat: -rw-r--r-- 868 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from pymongo.connection import Connection

id="GLPI"
records = []
con = Connection('localhost')
db = con.shinken
app = None # app is not otherwise
if not db:
    message = "Error : Unable to connect to mongo database"
#    return {'app': app, 'eue_data': {}, 'message': message }

parts = eueid.split(".")
parts.pop(0)
id =  ".".join(parts)

records=[]
for feature in db.eue.find({'key': { '$regex': id } }).sort("start_time",1).limit(100):
    date = feature["start_time"]
    failed = 0
    succeed = 0
    total = 0
    for scenario,scenario_data in feature["scenarios"].items():
        if scenario_data["status"] == 0:
            succeed += 1
        else:
            failed += 1

    total = succeed + failed
    records.append({
        "date" : int(date),
        "succeed" : succeed,
        "failed" : failed,
        "total" : total
    })

print records