2 """ Python test case for Log Import API wrapper module
5 # Copyright (C) 2012-2014 Red Hat Inc.
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 def check_import(archive
, hostname
, timezone
):
26 """ Test body - check many of the Log Import API wrapper interfaces
28 log
= pmi
.pmiLogImport(archive
)
29 log
.pmiSetHostname(hostname
)
30 log
.pmiSetTimezone(timezone
)
32 domain
= 60 # Linux kernel
33 pmid
= log
.pmiID(domain
, 2, 0)
34 indom
= log
.pmiInDom(domain
, 2)
35 units
= log
.pmiUnits(0, 0, 0, 0, 0, 0)
37 # create a metric with no instances (hinv.ncpu)
38 log
.pmiAddMetric("hinv.ncpu", cpmapi
.PM_ID_NULL
, cpmapi
.PM_TYPE_U32
,
39 cpmapi
.PM_INDOM_NULL
, cpmapi
.PM_SEM_DISCRETE
, units
)
42 log
.pmiPutValue("hinv.ncpu", "", "%d" % 42)
44 # create a metric with instances (kernel.all.load)
45 log
.pmiAddMetric("kernel.all.load", pmid
,
46 cpmapi
.PM_TYPE_FLOAT
, indom
, cpmapi
.PM_SEM_INSTANT
, units
)
47 log
.pmiAddInstance(indom
, "1 minute", 1)
48 log
.pmiAddInstance(indom
, "5 minute", 5)
49 log
.pmiAddInstance(indom
, "15 minute", 15)
52 log
.pmiPutValue("kernel.all.load", "1 minute", "%f" % 0.01)
53 log
.pmiPutValue("kernel.all.load", "5 minute", "%f" % 0.05)
54 log
.pmiPutValue("kernel.all.load", "15 minute", "%f" % 0.15)
56 timetuple
= math
.modf(time
.time())
57 useconds
= int(timetuple
[0] * 1000000)
58 seconds
= int(timetuple
[1])
59 log
.pmiWrite(seconds
, useconds
)
63 if __name__
== '__main__':
65 if (len(sys
.argv
) != 2):
66 print("Usage: " + sys
.argv
[0] + " <path>")
69 check_import(sys
.argv
[1], "www.abc.com", "EST-10")