Skip to content

Commit ca6bc56

Browse files
committed
api port management
Signed-off-by: hwassman <[email protected]>
1 parent ddef9dd commit ca6bc56

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

source/confParser.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def checkTLSsettings(args):
5858

5959
def checkApplicationPort(args):
6060
if not args.get('port', None) and not args.get('prometheus', None):
61-
return False, MSG['MissingParm']
61+
return False, MSG['MissingPortParam']
6262
return True, ''
6363

6464

@@ -89,6 +89,8 @@ def getSettings(argv):
8989
return None, msg
9090
# check application port
9191
valid, msg = checkApplicationPort(settings)
92+
if not valid:
93+
return None, msg
9294
# check API key settings
9395
valid, msg = checkAPIsettings(settings)
9496
if not valid:
@@ -115,6 +117,8 @@ def merge_defaults_and_args(defaults, args):
115117
brConfig[k] = False
116118
elif v == "yes" or v == "True":
117119
brConfig[k] = True
120+
elif isinstance(v, str) and v.isdigit():
121+
brConfig[k] = int(v)
118122
return brConfig
119123

120124

@@ -196,19 +200,31 @@ def parse_cmd_args(argv):
196200
help='Host name or ip address of the ZIMon collector (Default from config.ini: 127.0.0.1)')
197201
parser.add_argument('-P', '--serverPort', action="store", type=int, choices=[9980, 9981], default=None,
198202
help='ZIMon collector port number (Default from config.ini: 9980)')
199-
parser.add_argument('-l', '--logPath', action="store", default=None, help='location path of the log file (Default from config.ini: \'/var/log/ibm_bridge_for_grafana\')')
200-
parser.add_argument('-f', '--logFile', action="store", default=None, help='Name of the log file (Default from config.ini: zserver.log). If no log file name specified \
203+
parser.add_argument('-l', '--logPath', action="store", default=None,
204+
help='location path of the log file (Default from config.ini: \'/var/log/ibm_bridge_for_grafana\')')
205+
parser.add_argument('-f', '--logFile', action="store", default=None,
206+
help='Name of the log file (Default from config.ini: zserver.log). If no log file name specified \
201207
all traces will be printed out directly on the command line')
202208
parser.add_argument('-c', '--logLevel', action="store", type=int, default=None,
203209
help='log level. Available levels: 10 (DEBUG), 15 (MOREINFO), 20 (INFO), 30 (WARN), 40 (ERROR) (Default from config.ini: 15)')
204-
parser.add_argument('-p', '--port', action="store", type=int, default=None, help='port number listening on HTTP(S) client connections (Default from config.ini: 4242)')
205-
parser.add_argument('-r', '--protocol', action="store", choices=["http", "https"], default=None, help='Connection protocol HTTP/HTTPS (Default from config.ini: "http")')
206-
parser.add_argument('-t', '--tlsKeyPath', action="store", default=None, help='Directory path of tls privkey.pem and cert.pem file location (Required only for HTTPS port 8443)')
207-
parser.add_argument('-k', '--tlsKeyFile', action="store", default=None, help='Name of TLS key file, f.e.: privkey.pem (Required only for HTTPS port 8443)')
208-
parser.add_argument('-m', '--tlsCertFile', action="store", default=None, help='Name of TLS certificate file, f.e.: cert.pem (Required only for HTTPS port 8443)')
209-
parser.add_argument('-n', '--apiKeyName', action="store", default=None, help='Name of api key file (Default from config.ini: \'scale_grafana\')')
210-
parser.add_argument('-v', '--apiKeyValue', action=Password, nargs='?', dest='apiKeyValue', default=None, help='Enter your apiKey value:')
211-
parser.add_argument('-d', '--includeDiskData', action="store", choices=["yes", "no"], default=None, help='Use or not the historical data from disk (Default from config.ini: "no")')
210+
parser.add_argument('-e', '--prometheus', action="store", default=None,
211+
help='port number listening on Prometheus HTTPS connections (Default from config.ini: 9250, if enabled)')
212+
parser.add_argument('-p', '--port', action="store", default=None,
213+
help='port number listening on OpenTSDB API HTTP(S) connections (Default from config.ini: 4242, if enabled)')
214+
parser.add_argument('-r', '--protocol', action="store", choices=["http", "https"], default=None,
215+
help='Connection protocol HTTP/HTTPS (Default from config.ini: "http")')
216+
parser.add_argument('-t', '--tlsKeyPath', action="store", default=None,
217+
help='Directory path of tls privkey.pem and cert.pem file location (Required only for HTTPS ports 8443/9250)')
218+
parser.add_argument('-k', '--tlsKeyFile', action="store", default=None,
219+
help='Name of TLS key file, f.e.: privkey.pem (Required only for HTTPS ports 8443/9250)')
220+
parser.add_argument('-m', '--tlsCertFile', action="store", default=None,
221+
help='Name of TLS certificate file, f.e.: cert.pem (Required only for HTTPS ports 8443/9250)')
222+
parser.add_argument('-n', '--apiKeyName', action="store", default=None,
223+
help='Name of api key file (Default from config.ini: \'scale_grafana\')')
224+
parser.add_argument('-v', '--apiKeyValue', action=Password, nargs='?', dest='apiKeyValue', default=None,
225+
help='Enter your apiKey value:')
226+
parser.add_argument('-d', '--includeDiskData', action="store", choices=["yes", "no"], default=None,
227+
help='Use or not the historical data from disk (Default from config.ini: "no")')
212228

213229
args = parser.parse_args(argv)
214230
return args, ''

source/config.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# 4242 - for HTTP connections
77
# 8443 - for HTTPS connections
88
# (Default: 4242)
9-
port = 4242
9+
# port = 4242
1010

1111
# Protocol (http, https)
1212
protocol = http
@@ -18,7 +18,7 @@ protocol = http
1818

1919
# Sensor counters deltas will be exported by default.
2020
# Set True if you want export original sensor counters.
21-
# rawCounters = False
21+
rawCounters = True
2222

2323

2424
#################################### API SSL OAuth ############################

source/messages.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
MSG = {'IntError': 'Server internal error occurred. Reason: {}',
2929
'sysStart': 'Initial cherryPy server engine start have been invoked. Python version: {}, cherryPy version: {}.',
3030
'MissingParm': 'Missing mandatory parameters, quitting',
31+
'MissingPortParam': 'Missing applications port configuration, quitting',
3132
'MissingSSLCert': 'Missing ssl configuration, quitting',
3233
'KeyPathError': 'KeyPath directory not found, quitting',
3334
'CertError': 'Missing certificates in the specified keyPath directory, quitting',
@@ -55,7 +56,7 @@
5556
'ReceivAttrValues': 'Received {}:{}',
5657
'StartMethod': 'Starting method: {} with args: {}.',
5758
'RunMethod': 'Executed method: {} with args: {}.',
58-
'TimerInfo': 'Processing {} took {:.3f} seconds.',
59+
'TimerInfo': 'Processing {} took {:.6f} seconds.',
5960
'Query2port': 'For better bridge performance multithreaded port {} will be used',
6061
'CollectorConnInfo': 'Connection to the collector server established successfully',
6162
'BridgeVersionInfo': ' *** IBM Storage Scale bridge for Grafana - Version: {} ***',
@@ -72,5 +73,6 @@
7273
'StartCustomThread': 'Started custom thread {}',
7374
'StopCustomThread': 'Stopped custom thread {}',
7475
'MetricInResults': 'Metric {} is in Collector.metrcs',
75-
'MetricNotInResults': 'Metric {} is not in Collector.metrcs'
76+
'MetricNotInResults': 'Metric {} is not in Collector.metrcs',
77+
'ConnApplications': 'Registered applications: \n {}'
7678
}

source/zimonGrafanaIntf.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def main(argv):
183183
print(msg)
184184
return
185185

186+
registered_apps = []
187+
186188
# prepare the logger
187189
logger = configureLogging(args.get('logPath'), args.get('logFile', None),
188190
args.get('logLevel'))
@@ -277,6 +279,8 @@ def main(argv):
277279
}
278280
)
279281

282+
registered_apps.append("OpenTSDB Api listening on Grafana queries")
283+
280284
if args.get('prometheus', None):
281285
bind_prometheus_server(args)
282286
load_endpoints('prometheus_endpoints.json')
@@ -294,7 +298,7 @@ def main(argv):
294298
}
295299
)
296300
# query for list configured zimon sensors
297-
cherrypy.tree.mount(api, '/sensorsconfig',
301+
cherrypy.tree.mount(exporter, '/sensorsconfig',
298302
{'/':
299303
{'request.dispatch': cherrypy.dispatch.MethodDispatcher()}
300304
}
@@ -312,6 +316,7 @@ def main(argv):
312316
{'request.dispatch': cherrypy.dispatch.MethodDispatcher()}
313317
}
314318
)
319+
registered_apps.append("Prometheus Exporter Api listening on Prometheus requests")
315320

316321
logger.info("%s", MSG['sysStart'].format(sys.version, cherrypy.__version__))
317322

@@ -322,6 +327,7 @@ def main(argv):
322327
cherrypy.engine.subscribe('stop', watcher.stop_watch)
323328
cherrypy.engine.start()
324329
cherrypy.engine.log('test')
330+
logger.info("%s", MSG['ConnApplications'].format(",\n ".join(registered_apps)))
325331
logger.info("server started")
326332
with open("/proc/{}/stat".format(os.getpid())) as f:
327333
data = f.read()
@@ -339,7 +345,7 @@ def main(argv):
339345
cherrypy.engine.stop()
340346
cherrypy.engine.exit()
341347

342-
api = None
348+
api = exporter = None
343349

344350
logger.warning("server stopped")
345351

0 commit comments

Comments
 (0)