Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARGO-2682 Tenant separated logs files #272

Open
wants to merge 5 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion exec/downtimes-csv-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from argo_connectors.log import Logger
from argo_connectors.tasks.flat_downtimes import TaskCsvDowntimes
from argo_connectors.tasks.common import write_state
from argo_connectors.utils import parse_conf_path

from argo_connectors.config import Global, CustomerConf

Expand All @@ -37,13 +38,16 @@ def main():
parser.add_argument('-g', dest='gloconf', nargs=1, metavar='global.conf', help='path to global configuration file', type=str, required=False)
args = parser.parse_args()

logger = Logger(os.path.basename(sys.argv[0]))
confpath = args.gloconf[0] if args.gloconf else None
cglob = Global(sys.argv[0], confpath)
globopts = cglob.parse()

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
6 changes: 5 additions & 1 deletion exec/downtimes-gocdb-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from argo_connectors.log import Logger
from argo_connectors.tasks.gocdb_downtimes import TaskGocdbDowntimes
from argo_connectors.tasks.common import write_state
from argo_connectors.utils import parse_conf_path

from argo_connectors.config import Global, CustomerConf

Expand Down Expand Up @@ -42,13 +43,16 @@ def main():
help='path to global configuration file', type=str, required=False)
args = parser.parse_args()

logger = Logger(os.path.basename(sys.argv[0]))
confpath = args.gloconf[0] if args.gloconf else None
cglob = Global(sys.argv[0], confpath)
globopts = cglob.parse()

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
7 changes: 5 additions & 2 deletions exec/metricprofile-webapi-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from argo_connectors.config import CustomerConf, Global
from argo_connectors.log import Logger
from argo_connectors.tasks.webapi_metricprofile import TaskWebApiMetricProfile
from argo_connectors.utils import date_check
from argo_connectors.utils import date_check, parse_conf_path

logger = None

Expand All @@ -26,7 +26,6 @@ def main():
parser.add_argument('-d', dest='date', metavar='YEAR-MONTH-DAY', help='write data for this date', type=str, required=False)
args = parser.parse_args()

logger = Logger(os.path.basename(sys.argv[0]))

fixed_date = None
if args.date and date_check(args.date):
Expand All @@ -38,6 +37,10 @@ def main():

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
7 changes: 5 additions & 2 deletions exec/service-types-csv-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from argo_connectors.log import Logger
from argo_connectors.tasks.flat_servicetypes import TaskFlatServiceTypes
from argo_connectors.tasks.common import write_state
from argo_connectors.utils import date_check
from argo_connectors.utils import date_check, parse_conf_path

from argo_connectors.config import Global, CustomerConf

Expand Down Expand Up @@ -43,13 +43,16 @@ def main():
if args.date and date_check(args.date):
fixed_date = args.date

logger = Logger(os.path.basename(sys.argv[0]))
confpath = args.gloconf[0] if args.gloconf else None
cglob = Global(sys.argv[0], confpath)
globopts = cglob.parse()

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
7 changes: 5 additions & 2 deletions exec/service-types-gocdb-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from argo_connectors.log import Logger
from argo_connectors.tasks.gocdb_servicetypes import TaskGocdbServiceTypes
from argo_connectors.tasks.common import write_state
from argo_connectors.utils import date_check
from argo_connectors.utils import date_check, parse_conf_path

from argo_connectors.config import Global, CustomerConf

Expand Down Expand Up @@ -43,13 +43,16 @@ def main():
if args.date and date_check(args.date):
fixed_date = args.date

logger = Logger(os.path.basename(sys.argv[0]))
confpath = args.gloconf[0] if args.gloconf else None
cglob = Global(sys.argv[0], confpath)
globopts = cglob.parse()

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
7 changes: 5 additions & 2 deletions exec/service-types-json-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from argo_connectors.log import Logger
from argo_connectors.tasks.flat_servicetypes import TaskFlatServiceTypes
from argo_connectors.tasks.common import write_state
from argo_connectors.utils import date_check
from argo_connectors.utils import date_check, parse_conf_path

from argo_connectors.config import Global, CustomerConf

Expand Down Expand Up @@ -43,13 +43,16 @@ def main():
if args.date and date_check(args.date):
fixed_date = args.date

logger = Logger(os.path.basename(sys.argv[0]))
confpath = args.gloconf[0] if args.gloconf else None
cglob = Global(sys.argv[0], confpath)
globopts = cglob.parse()

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
7 changes: 5 additions & 2 deletions exec/topology-agora-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from argo_connectors.exceptions import ConnectorError, ConnectorHttpError, ConnectorParseError
from argo_connectors.log import Logger
from argo_connectors.config import Global, CustomerConf
from argo_connectors.utils import date_check
from argo_connectors.utils import date_check, parse_conf_path
from argo_connectors.tasks.agora_topology import TaskProviderTopology
from argo_connectors.tasks.common import write_state

Expand Down Expand Up @@ -39,7 +39,6 @@ def main():
parser.add_argument('-d', dest='date', metavar='YEAR-MONTH-DAY', help='write data for this date', type=str, required=False)
args = parser.parse_args()

logger = Logger(os.path.basename(sys.argv[0]))
fixed_date = None
if args.date and date_check(args.date):
fixed_date = args.date
Expand All @@ -50,6 +49,10 @@ def main():

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
7 changes: 5 additions & 2 deletions exec/topology-csv-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from argo_connectors.log import Logger
from argo_connectors.tasks.common import write_state
from argo_connectors.tasks.flat_topology import TaskFlatTopology
from argo_connectors.utils import date_check
from argo_connectors.utils import date_check, parse_conf_path

logger = None

Expand Down Expand Up @@ -41,7 +41,6 @@ def main():
parser.add_argument('-g', dest='gloconf', nargs=1, metavar='global.conf', help='path to global configuration file', type=str, required=False)
parser.add_argument('-d', dest='date', metavar='YEAR-MONTH-DAY', help='write data for this date', type=str, required=False)
args = parser.parse_args()
logger = Logger(os.path.basename(sys.argv[0]))

fixed_date = None
if args.date and date_check(args.date):
Expand All @@ -53,6 +52,10 @@ def main():

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
7 changes: 5 additions & 2 deletions exec/topology-gocdb-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from argo_connectors.log import Logger
from argo_connectors.tasks.common import write_state
from argo_connectors.tasks.gocdb_topology import TaskGocdbTopology
from argo_connectors.utils import date_check
from argo_connectors.utils import date_check, parse_conf_path

logger = None
globopts = {}
Expand Down Expand Up @@ -58,7 +58,6 @@ def main():
help='write data for this date', type=str, required=False)
args = parser.parse_args()
group_endpoints, group_groups = [], []
logger = Logger(os.path.basename(sys.argv[0]))

fixed_date = None
if args.date and date_check(args.date):
Expand All @@ -71,6 +70,10 @@ def main():

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
7 changes: 5 additions & 2 deletions exec/topology-json-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from argo_connectors.log import Logger
from argo_connectors.tasks.common import write_state
from argo_connectors.tasks.flat_topology import TaskFlatTopology
from argo_connectors.utils import date_check
from argo_connectors.utils import date_check, parse_conf_path

logger = None
globopts = {}
Expand Down Expand Up @@ -40,7 +40,6 @@ def main():
parser.add_argument('-d', dest='date', metavar='YEAR-MONTH-DAY', help='write data for this date', type=str, required=False)
args = parser.parse_args()
group_endpoints, group_groups = list(), list()
logger = Logger(os.path.basename(sys.argv[0]))

fixed_date = None
if args.date and date_check(args.date):
Expand All @@ -52,6 +51,10 @@ def main():

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
7 changes: 5 additions & 2 deletions exec/topology-provider-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from argo_connectors.io.statewrite import state_write
from argo_connectors.log import Logger
from argo_connectors.config import Global, CustomerConf
from argo_connectors.utils import filename_date, datestamp, date_check
from argo_connectors.utils import filename_date, datestamp, date_check, parse_conf_path
from argo_connectors.tasks.provider_topology import TaskProviderTopology
from argo_connectors.tasks.common import write_state

Expand Down Expand Up @@ -41,7 +41,6 @@ def main():
parser.add_argument('-d', dest='date', metavar='YEAR-MONTH-DAY', help='write data for this date', type=str, required=False)
args = parser.parse_args()
group_endpoints, group_groups = list(), list()
logger = Logger(os.path.basename(sys.argv[0]))

fixed_date = None
if args.date and date_check(args.date):
Expand All @@ -53,6 +52,10 @@ def main():

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)
tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
8 changes: 6 additions & 2 deletions exec/weights-vapor-connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from argo_connectors.log import Logger

from argo_connectors.config import Global, CustomerConf
from argo_connectors.utils import date_check
from argo_connectors.utils import date_check, parse_conf_path

globopts = {}
logger = None
Expand All @@ -31,7 +31,6 @@ def main():
help='write data for this date', type=str, required=False)
args = parser.parse_args()

logger = Logger(os.path.basename(sys.argv[0]))

fixed_date = None
if args.date and date_check(args.date):
Expand All @@ -43,6 +42,11 @@ def main():

confpath = args.custconf[0] if args.custconf else None
confcust = CustomerConf(sys.argv[0], confpath)

tenant_name = parse_conf_path(confpath)

logger = Logger(os.path.basename(sys.argv[0]), tenant_name)

confcust.parse()
confcust.make_dirstruct()
confcust.make_dirstruct(globopts['InputStateSaveDir'.lower()])
Expand Down
4 changes: 2 additions & 2 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Global(object):
def __init__(self, caller, confpath=None, **kwargs):
self.optional = dict()

self.logger = Logger(str(self.__class__))
self.logger = Logger(str(self.__class__), tenant_name=None)
self._filename = '/etc/argo-connectors/global.conf' if not confpath else confpath
self._checkpath = kwargs['checkpath'] if 'checkpath' in kwargs.keys(
) else False
Expand Down Expand Up @@ -228,7 +228,7 @@ class CustomerConf(object):
deftopofeed = 'https://goc.egi.eu/gocdbpi/'

def __init__(self, caller, confpath, **kwargs):
self.logger = Logger(str(self.__class__))
self.logger = Logger(str(self.__class__), tenant_name=None)
self._filename = '/etc/argo-connectors/customer.conf' if not confpath else confpath
if not kwargs:
self._jobattrs = self._defjobattrs[os.path.basename(caller)]
Expand Down
9 changes: 6 additions & 3 deletions modules/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
import logging.handlers
import sys
import socket

LOGFILE = "/var/log/argo-connectors/connectors.log"
import os


class Logger:
def __init__(self, connector):
def __init__(self, connector, tenant_name):
lfs = '%(name)s[%(process)s]: %(levelname)s %(message)s'
logformat = logging.Formatter(lfs)
logverbose = logging.INFO
self.connector = connector
self.tenant_name = tenant_name

if self.tenant_name is not None:
LOGFILE = f"/var/log/argo-connectors/connectors-{self.tenant_name}.log"

logging.basicConfig(format=lfs, level=logging.INFO, stream=sys.stdout)
self.logger = logging.getLogger(connector)
Expand Down
8 changes: 7 additions & 1 deletion modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ def remove_non_utf(string):
if '"' in string:
string = string.replace('"', '')

return unidecode(string)
return unidecode(string)


def parse_conf_path(path):
tenant = path.split('/')[3].split('-')[0]

return tenant.upper()
2 changes: 1 addition & 1 deletion tests/test_bdiisepath.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from bonsai import LDAPEntry


logger = Logger('test_contactfeed.py')
logger = Logger('test_contactfeed.py', 'foo_tenant')
CUSTOMER_NAME = 'CUSTOMERFOO'


Expand Down
Loading