/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React, { useState, useEffect } from "react"; import HeaderPanel from "components/HeaderPanel"; import FormItem from "components/FormItem"; import Tiles from "components/Tiles"; import PagePanel from "components/PagePanel"; import Select from "components/Select"; import { getLogConf, listLogConfs } from "graphql/queries"; import { appSyncRequestQuery } from "assets/js/request"; import { SelectItem } from "components/Select/select"; import { LogSourceType, LogType, MultiLineLogParser, SyslogParser } from "API"; import { CreationMethod } from "types"; import LogConfigComp, { ExLogConf, PageType, } from "pages/resources/common/LogConfigComp"; import { INVALID, RFC3164_DEFAULT_REGEX, RFC5424_DEFAULT_REGEX, } from "assets/js/const"; import { getRegexAndTimeByConfigAndFormat } from "assets/js/utils"; import { useTranslation } from "react-i18next"; import CreateSampleDashboard from "pages/dataInjection/applicationLog/common/CreateSampleDashboard"; import { InfoBarTypes } from "reducer/appReducer"; import TextInput from "components/TextInput"; import ConfigDetailComps from "pages/resources/logConfig/ConfigDetailComps"; import LoadingText from "components/LoadingText"; import { IngestionPropsType } from "../createIngestion/CreateIngestion"; import { IngestionFromSysLogPropsType } from "../createSyslogIngestion/CreateSysLogIngestion"; import { IngestionFromEKSPropsType } from "../createEKSIngestion/CreateEKSIngestion"; interface ApplyConfigProps { hideLogPath: boolean; ingestionInfo: | IngestionPropsType | IngestionFromSysLogPropsType | IngestionFromEKSPropsType; logSourceType?: LogSourceType; changeCurLogConfig: (config: ExLogConf) => void; changeSampleDashboard: (yesNo: string) => void; hideNameError: () => void; hideTypeError: () => void; changeLoadingConfig: (loading: boolean) => void; changeLogCreationMethod: (method: string) => void; changeUserLogFormatError: (error: boolean) => void; changeSampleLogFormatInvalid: (invalid: boolean) => void; changeLogPath: (path: string) => void; changeExistsConfig: (configId: string) => void; } const ApplyLogConfig: React.FC = ( props: ApplyConfigProps ) => { const { hideLogPath, ingestionInfo, logSourceType, changeCurLogConfig, changeSampleDashboard, hideNameError, hideTypeError, changeLoadingConfig, changeLogCreationMethod, changeUserLogFormatError, changeSampleLogFormatInvalid, changeLogPath, changeExistsConfig, } = props; const { t } = useTranslation(); const [loadingConfig, setLoadingConfig] = useState(false); const [loadingData, setLoadingData] = useState(false); const [logConfigOptionList, setLogConfigOptionList] = useState( [] ); const getLogConfigById = async (confId: string) => { try { setLoadingData(true); changeLoadingConfig(true); const resData: any = await appSyncRequestQuery(getLogConf, { id: confId, }); console.info("resData:", resData); const dataLogConfig: ExLogConf = resData.data.getLogConf; changeCurLogConfig(dataLogConfig); hideNameError(); hideTypeError(); setLoadingData(false); changeLoadingConfig(false); } catch (error) { setLoadingData(false); changeLoadingConfig(false); console.error(error); } }; // Get Instance Group List const getLogConfigList = async () => { try { setLoadingConfig(true); changeLoadingConfig(true); const resData: any = await appSyncRequestQuery(listLogConfs, { page: 1, count: 9999, }); console.info("resData:", resData); const dataLogConfList: ExLogConf[] = resData.data.listLogConfs.logConfs; const tmpConfigOptList: SelectItem[] = []; if (dataLogConfList && dataLogConfList.length > 0) { // Only set config list with json and single line regex when ingest syslog if (logSourceType === LogSourceType.Syslog) { dataLogConfList.forEach((element) => { if ( element.logType === LogType.JSON || element.logType === LogType.SingleLineText || element.logType === LogType.Syslog ) { tmpConfigOptList.push({ name: element.confName || "", value: element.id, }); } }); } else { dataLogConfList.forEach((element) => { tmpConfigOptList.push({ name: element.confName || "", value: element.id, }); }); } } setLogConfigOptionList(tmpConfigOptList); setLoadingConfig(false); changeLoadingConfig(false); } catch (error) { setLoadingConfig(false); changeLoadingConfig(false); console.error(error); } }; useEffect(() => { if (ingestionInfo.logConfigMethod === CreationMethod.Exists) { getLogConfigList(); hideNameError(); hideTypeError(); } }, [ingestionInfo.logConfigMethod]); useEffect(() => { console.info( "ingestionInfo.curLogConfig?.id:", ingestionInfo.curLogConfig?.id ); if (ingestionInfo.curLogConfig?.id) { getLogConfigById(ingestionInfo.curLogConfig?.id); } }, [ingestionInfo.curLogConfig?.id]); return (
{!hideLogPath && (
_*" : "/var/log/app1/*.log, /var/log/app2/*.log" } onChange={(event) => { changeLogPath(event.target.value); }} />
)}
{ changeExistsConfig(""); changeLogCreationMethod(event.target.value); }} items={[ { label: t("applog:ingestion.applyConfig.new"), description: t("applog:ingestion.applyConfig.newDesc"), value: CreationMethod.New, }, { label: t("applog:ingestion.applyConfig.exists"), description: t("applog:ingestion.applyConfig.existsDesc"), value: CreationMethod.Exists, }, ]} /> {ingestionInfo.logConfigMethod === CreationMethod.Exists && (