~mmenkhof/+junk/lds_reporting_API_scripts

« back to all changes in this revision

Viewing changes to landscape_GetUSNTimeToFix.py

  • Committer: Malte Menkhoff
  • Date: 2014-08-25 10:54:46 UTC
  • Revision ID: malte.menkhoff@canonica.com-20140825105446-fl8qf1gl8atldcki
inital creation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
import os, json, sys, re, pprint
 
3
from landscape_api.base import API, HTTPError
 
4
 
 
5
# change these accordingly
 
6
uri = "https://landscape.canonical.com/api/"
 
7
key = "<please insert your key here>"
 
8
secret = "<pleaseinsert your secret here>"
 
9
 
 
10
if key == "<please insert your key here>":
 
11
        print "please add your personal key in file"
 
12
        sys.exit(1)
 
13
 
 
14
if key == "<please insert your secret here>":
 
15
        print "please add your personal secret in file"
 
16
        sys.exit(1)
 
17
 
 
18
api = API(uri, key, secret)
 
19
try:
 
20
    usns= api.get_usn_time_to_fix(query="in_last=30")
 
21
except HTTPError, e:
 
22
    print ("\nGot server error:\n"
 
23
           "Code: %d\n"
 
24
           "Message: %s\n") % (e.code, e.message)
 
25
    sys.exit(1)
 
26
 
 
27
print "USN analyze for the last 30 days:"
 
28
print "#################################"
 
29
 
 
30
if len(usns) == 0:
 
31
        print "No USN data available"
 
32
else:
 
33
        for values in sorted(usns, key=len):
 
34
                print "USNs patched within a range of ", values, "days =>", usns[values]