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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#
# Copyright (C) 2014 Red Hat.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
import sys as system
from pcp import pmapi
import cpmapi as c_api
""" Create an options object and set/get everything possible """
options = pmapi.pmOptions("a:bfl:D:h:H:K:LS:T:O:A:s:t:VZ:z?")
options.pmSetOptionFlags(c_api.PM_OPTFLAG_BOUNDARIES)
options.pmSetOptionFlags(c_api.PM_OPTFLAG_MULTI)
options.pmSetOptionFlags(c_api.PM_OPTFLAG_MIXED)
options.pmSetLongOptionHeader("General Options")
options.pmSetLongOptionAlign()
options.pmSetLongOptionArchive()
options.pmSetLongOptionDebug()
options.pmSetLongOptionGuiMode()
options.pmSetLongOptionHost()
options.pmSetLongOptionHostsFile()
options.pmSetLongOptionSpecLocal()
options.pmSetLongOptionLocalPMDA()
options.pmSetLongOptionOrigin()
options.pmSetLongOptionGuiPort()
options.pmSetLongOptionStart()
options.pmSetLongOptionSamples()
options.pmSetLongOptionFinish()
options.pmSetLongOptionInterval()
options.pmSetLongOptionVersion()
options.pmSetLongOptionTimeZone()
options.pmSetLongOptionHostZone()
options.pmSetLongOptionHelp()
# extract any options we can (many are consumed internally) & dump 'em;
# this test variant focusses on context creation and using time windows.
ctx = c_api.PM_ERR_NOCONTEXT
try:
ctx = pmapi.pmContext.fromOptions(options, system.argv)
except pmapi.pmUsageErr as usage:
usage.message()
system.exit(1)
except pmapi.pmErr as error:
print(error)
nonoptions = options.pmNonOptionsFromList(system.argv)
if nonoptions != None:
print("Non-option arguments: %s" % nonoptions)
# for host and archive lists exercise the creation of multiple contexts
hosts = options.pmGetOptionHosts()
if hosts != None:
print("Host list: %s" % hosts)
print("Host %s pmcd.hostname: %s" % (hosts[0], ctx.pmGetContextHostName()))
if len(hosts) > 1:
typed = c_api.PM_CONTEXT_HOST
for index in range(1, len(hosts)):
try:
ctx = pmapi.pmContext.fromOptions(options, system.argv, typed, index)
print("Host %s pmcd.hostname: %s" % (hosts[index], ctx.pmGetContextHostName()))
except pmapi.pmErr as error:
print("pmContext failed for host %s - %s" %s (hosts[index], error))
archives = options.pmGetOptionArchives()
if archives != None:
print("Archive list: %s" % archives)
print("Archive %s hostname: %s" % (archives[0], ctx.pmGetContextHostName()))
if len(archives) > 1:
typed = c_api.PM_CONTEXT_ARCHIVE
for index in range(1, len(archives)):
try:
ctx = pmapi.pmContext.fromOptions(options, system.argv, typed, index)
print("Archive %s hostname: %s" % (archives[index], ctx.pmGetContextHostName()))
except pmapi.pmErr as error:
print("pmContext failed for archive %s - %s" % (archives[index], error))
timezone = options.pmGetOptionTimezone()
if timezone != None:
print("Timezone: %s" % timezone)
samples = options.pmGetOptionSamples()
if samples != None:
print("Samples: %d" % samples)
interval = options.pmGetOptionInterval()
if interval != None:
print("Interval: %s" % interval)
start = options.pmGetOptionStart()
if start != None:
print("Start: %s" % start)
finish = options.pmGetOptionFinish()
if finish != None:
print("Finish: %s" % finish)
origin = options.pmGetOptionOrigin()
if origin != None:
print("Origin: %s" % origin)
print("Done!")
|