mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-27 03:04:16 +03:00
Merge pull request #1395 from EmilienMottet/add-auth-provider-cassandra
add authprovider for cassandra export
This commit is contained in:
commit
067e1981c2
@ -365,6 +365,9 @@ keyspace=glances
|
|||||||
replication_factor=2
|
replication_factor=2
|
||||||
# If not define, table name is set to host key
|
# If not define, table name is set to host key
|
||||||
table=localhost
|
table=localhost
|
||||||
|
# If not define, username and password will not be used
|
||||||
|
#username=cassandra
|
||||||
|
#password=password
|
||||||
|
|
||||||
[opentsdb]
|
[opentsdb]
|
||||||
# Configuration for the --export opentsdb option
|
# Configuration for the --export opentsdb option
|
||||||
|
@ -27,6 +27,7 @@ from glances.logger import logger
|
|||||||
from glances.exports.glances_export import GlancesExport
|
from glances.exports.glances_export import GlancesExport
|
||||||
from glances.compat import iteritems
|
from glances.compat import iteritems
|
||||||
|
|
||||||
|
from cassandra.auth import PlainTextAuthProvider
|
||||||
from cassandra.cluster import Cluster
|
from cassandra.cluster import Cluster
|
||||||
from cassandra.util import uuid_from_time
|
from cassandra.util import uuid_from_time
|
||||||
from cassandra import InvalidRequest
|
from cassandra import InvalidRequest
|
||||||
@ -47,13 +48,17 @@ class Export(GlancesExport):
|
|||||||
self.protocol_version = 3
|
self.protocol_version = 3
|
||||||
self.replication_factor = 2
|
self.replication_factor = 2
|
||||||
self.table = None
|
self.table = None
|
||||||
|
self.username = None
|
||||||
|
self.password = None
|
||||||
|
|
||||||
# Load the Cassandra configuration file section
|
# Load the Cassandra configuration file section
|
||||||
self.export_enable = self.load_conf('cassandra',
|
self.export_enable = self.load_conf('cassandra',
|
||||||
mandatories=['host', 'port', 'keyspace'],
|
mandatories=['host', 'port', 'keyspace'],
|
||||||
options=['protocol_version',
|
options=['protocol_version',
|
||||||
'replication_factor',
|
'replication_factor',
|
||||||
'table'])
|
'table',
|
||||||
|
'username',
|
||||||
|
'password'])
|
||||||
if not self.export_enable:
|
if not self.export_enable:
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
@ -61,15 +66,20 @@ class Export(GlancesExport):
|
|||||||
self.cluster, self.session = self.init()
|
self.cluster, self.session = self.init()
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""Init the connection to the InfluxDB server."""
|
"""Init the connection to the Cassandra server."""
|
||||||
if not self.export_enable:
|
if not self.export_enable:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# if username and/or password are not set the connection will try to connect with no auth
|
||||||
|
auth_provider = PlainTextAuthProvider(
|
||||||
|
username=self.username, password=self.password)
|
||||||
|
|
||||||
# Cluster
|
# Cluster
|
||||||
try:
|
try:
|
||||||
cluster = Cluster([self.host],
|
cluster = Cluster([self.host],
|
||||||
port=int(self.port),
|
port=int(self.port),
|
||||||
protocol_version=int(self.protocol_version))
|
protocol_version=int(self.protocol_version),
|
||||||
|
auth_provider=auth_provider)
|
||||||
session = cluster.connect()
|
session = cluster.connect()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical("Cannot connect to Cassandra cluster '%s:%s' (%s)" % (self.host, self.port, e))
|
logger.critical("Cannot connect to Cassandra cluster '%s:%s' (%s)" % (self.host, self.port, e))
|
||||||
|
Loading…
Reference in New Issue
Block a user