/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates, or * a third party where indicated. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "CloudGemDefectReporter_precompiled.h" #include #include #include #include #include #include #include #include #include namespace CloudGemDefectReporter { NetworkInfoCollectingJob::NetworkInfoCollectingJob(AZ::JobContext* jobContext, const AZStd::vector& domainNames, int reportId, int handlerId) : AZ::Job(true, jobContext), m_jobContext(jobContext), m_domainNames(domainNames), m_reporId(reportId), m_handlerId(handlerId) { } void NetworkInfoCollectingJob::Process() { if (m_domainNames.size() == 0) { return; } AZStd::vector tracerouteResults; tracerouteResults.resize(m_domainNames.size()); AZStd::vector nslookupResults; nslookupResults.resize(m_domainNames.size()); for (int i = 0; i < m_domainNames.size(); i++) { AZStd::string& domainName = m_domainNames[i]; { AZStd::string& tracerouteResult = tracerouteResults[i]; auto job = AZ::CreateJobFunction([this, domainName, &tracerouteResult]() { Traceroute traceroute; tracerouteResult = traceroute.GetResult(domainName); }, true, m_jobContext); StartAsChild(job); } { AZStd::string& nslookupResult = nslookupResults[i]; auto job = AZ::CreateJobFunction([this, domainName, &nslookupResult]() { NSLookup nslookup; nslookupResult = nslookup.GetResult(domainName); }, true, m_jobContext); StartAsChild(job); } } WaitForChildren(); AZStd::vector metrics; { MetricDesc metricDesc; metricDesc.m_key = "traceroute"; metricDesc.m_data = CombineResults(tracerouteResults); metrics.emplace_back(metricDesc); } { MetricDesc metricDesc; metricDesc.m_key = "nslookup"; metricDesc.m_data = CombineResults(nslookupResults); metrics.emplace_back(metricDesc); } CloudGemDefectReporterRequestBus::QueueBroadcast(&CloudGemDefectReporterRequestBus::Events::ReportData, m_reporId, m_handlerId, metrics, AZStd::vector()); } AZStd::string NetworkInfoCollectingJob::CombineResults(const AZStd::vector& results) const { AZStd::string out; for (auto& result : results) { if (result.empty()) { continue; } if (!out.empty()) { out += m_resultSeparator; } out += result; } return out; } }