1 martin 1.10 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.11 //
|
3 martin 1.10 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.11 //
|
10 martin 1.10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.11 //
|
17 martin 1.10 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.11 //
|
20 martin 1.10 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.11 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.10 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.11 //
|
28 martin 1.10 //////////////////////////////////////////////////////////////////////////
|
29 kumpf 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <cstring>
33
34
35 // Using the general CIMOM TestClient as an example, developed an
36 // ntpinfo client that does an enumerateInstances of the
37 // PG_NTPService class and displays properties of interest.
38
|
39 kumpf 1.12 // At this time, there is only one instance of PG_NTPService.
|
40 kumpf 1.1
|
41 kumpf 1.12 #include "NTPInfo.h"
|
42 kumpf 1.1
43 PEGASUS_USING_PEGASUS;
44 PEGASUS_USING_STD;
45
46 #define NAMESPACE CIMNamespaceName ("root/cimv2")
47 #define CLASSNAME CIMName ("PG_NTPService")
48
49 /** Constructor for NTPInfo Client
50 */
51
52 NTPInfo::NTPInfo(void)
53 {
|
54 karl 1.9 ntpSystemName = String::EMPTY;
55 ntpSystemCreationClassName = String::EMPTY;
56 ntpName = String::EMPTY;
57 ntpCreationClassName = String::EMPTY;
58 ntpCaption = String::EMPTY;
59 ntpDescription = String::EMPTY;
60 ntpServerAddress = NULL;
|
61 kumpf 1.1 }
62
63 NTPInfo::~NTPInfo(void)
64 {
|
65 kumpf 1.12 }
|
66 kumpf 1.1
67 /** ErrorExit - Print out the error message as an
68 and get out.
69 @param - Text for error message
70 @return - None, Terminates the program
71 @exception - This function terminates the program
72 */
73 void NTPInfo::errorExit(const String& message)
74 {
75 cerr << "ntpinfo error: " << message << endl;
76 exit(1);
77 }
78
79 /** _usage method for osinfo - only accept one option
80 -c for raw CIM formatting
81 */
82 void NTPInfo::_usage()
83 {
|
84 karl 1.9 cerr << "Usage: osinfo [-c]" << endl;
85 cerr << "Example:" << endl;
86 cerr << " ntpinfo " << endl;
87 cerr << " ntpinfo -c " << endl;
|
88 kumpf 1.1 }
89
90 /**
91 displayProperties method of the osinfo Test Client
92 */
93 void NTPInfo::displayProperties()
94 {
95 // interesting properties are stored off in class variables
96
|
97 kumpf 1.3 cout << "Network Time Protocol (NTP) Service Information" << endl;
|
98 kumpf 1.1 cout << endl;
99
100 // expect to have values for the keys (even if Unknown)
101 cout << " System Name : " << ntpSystemName << endl;
|
102 kumpf 1.12 cout << " System Creation Class Name : "
|
103 karl 1.9 << ntpSystemCreationClassName << endl;
|
104 kumpf 1.1 cout << " Name : " << ntpName << endl;
|
105 kumpf 1.3 cout << " Creation Class Name : " << ntpCreationClassName << endl;
|
106 kumpf 1.1 cout << " Caption : " << ntpCaption << endl;
107 cout << " Description : " << ntpDescription << endl;
|
108 kumpf 1.2 if (ntpServerAddress.size() == 0)
109 {
110 cout << " No NTP Servers Configured" << endl;
111 }
112 else
113 {
114 for (int i = 0; i <ntpServerAddress.size(); i++)
115 {
116 cout << " Server Address[" << i << "] : " <<
117 ntpServerAddress[i] << endl;
118 }
119 }
|
120 kumpf 1.1
121 }
122
123 /**
124 gatherProperties method of the osinfo Test Client
125 */
|
126 kumpf 1.12 void NTPInfo::gatherProperties(CIMInstance &inst, Boolean cimFormat)
|
127 kumpf 1.1 {
128 // don't have a try here - want it to be caught by caller
129
130 // loop through the properties
131 for (Uint32 j=0; j < inst.getPropertyCount(); j++)
132 {
133 CIMName propertyName = inst.getProperty(j).getName();
134
135 // only pull out those properties of interest
136 if (propertyName.equal (CIMName ("SystemName")))
137 {
138 inst.getProperty(j).getValue().get(ntpSystemName);
139 } // end if SystemName
140
141 if (propertyName.equal (CIMName ("SystemCreationClassName")))
142 {
143 inst.getProperty(j).getValue().get(ntpSystemCreationClassName);
144 } // end if SystemCreationClassName
|
145 kumpf 1.12
|
146 kumpf 1.1 if (propertyName.equal (CIMName ("Name")))
147 {
|
148 kumpf 1.12 inst.getProperty(j).getValue().get(ntpName);
|
149 kumpf 1.1 } // end if Name
150
151 if (propertyName.equal (CIMName ("CreationClassName")))
152 {
153 inst.getProperty(j).getValue().get(ntpCreationClassName);
154 } // end if CreationClassName
155
156 if (propertyName.equal (CIMName ("Caption")))
157 {
|
158 kumpf 1.12 inst.getProperty(j).getValue().get(ntpCaption);
|
159 kumpf 1.1 } // end if Caption
160
161 if (propertyName.equal (CIMName ("Description")))
162 {
|
163 kumpf 1.12 inst.getProperty(j).getValue().get(ntpDescription);
164 } // end if Description
|
165 kumpf 1.1
166 if (propertyName.equal (CIMName ("ServerAddress")))
167 {
|
168 kumpf 1.12 inst.getProperty(j).getValue().get(ntpServerAddress);
169 } // end if ServerAddress
|
170 kumpf 1.1 } // end of for looping through properties
171 }
172
|
173 kumpf 1.12 /*
174 getNTPInfo of the NTP provider.
|
175 kumpf 1.1 */
176 void NTPInfo::getNTPInfo(const int argc, const char** argv)
177 {
178
179 // ATTN-SLC-16-May-02-P1 enhance to take host & user info
|
180 kumpf 1.12 // Decided to keep local only for first release
|
181 kumpf 1.1
182 Boolean cimFormat = false;
183
184 // before we even connect to CIMOM, make sure we're
185 // syntactically valid
186
187 if (argc > 2)
188 {
189 _usage();
190 exit(1);
191 }
192
193 if (argc == 2)
194 {
195 // only support one option, -c for CIM formatting
196 const char *opt = argv[1];
197
198 if (strcmp(opt,"-c") == 0)
199 {
200 cimFormat = true;
201 }
202 kumpf 1.1 else
203 {
204 _usage();
205 exit(1);
206 }
207 }
208
209 // need to first connect to the CIMOM
210
211 try
212 {
213 // specify the timeout value for the connection (if inactive)
214 // in milliseconds, thus setting to one minute
215 CIMClient client;
216 client.setTimeout(60 * 1000);
|
217 karl 1.9 client.connectLocal();
|
218 kumpf 1.12
|
219 kumpf 1.1 Boolean deepInheritance = true;
220 Boolean localOnly = true;
221 Boolean includeQualifiers = false;
222 Boolean includeClassOrigin = false;
223 Uint32 numberInstances;
224
|
225 kumpf 1.12 Array<CIMInstance> cimNInstances =
226 client.enumerateInstances(NAMESPACE, CLASSNAME,
|
227 karl 1.9 deepInheritance,
228 localOnly, includeQualifiers,
229 includeClassOrigin );
|
230 kumpf 1.12
|
231 kumpf 1.1 numberInstances = cimNInstances.size();
232
233 // while we only have one instance (the running OS), we can take the
234 // first instance. When the OSProvider supports installed OSs as well,
235 // will need to select the runningOS instance
236
237 for (Uint32 i = 0; i < cimNInstances.size(); i++)
238 {
239 CIMObjectPath instanceRef = cimNInstances[i].getPath ();
240 if ( !(instanceRef.getClassName().equal (CIMName (CLASSNAME))))
241 {
242 errorExit("EnumerateInstances failed");
243 }
244
245 // first gather the interesting properties
246 gatherProperties(cimNInstances[i], cimFormat);
|
247 kumpf 1.12
|
248 kumpf 1.1 // then display them
249 displayProperties();
250
251 } // end for looping through instances
|
252 kumpf 1.12
253 } // end try
254
|
255 kumpf 1.1 catch(Exception& e)
256 {
257 errorExit(e.getMessage());
258 }
259
260 }
261
262 ///////////////////////////////////////////////////////////////
263 // MAIN
264 ///////////////////////////////////////////////////////////////
265
266 int main(const int argc, const char** argv)
267 {
268 NTPInfo ntpInfo;
269 ntpInfo.getNTPInfo(argc, argv);
270 return 0;
271 }
272
|