Skip to content

Collect agent information #152

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

Merged
merged 1 commit into from
Jun 18, 2025
Merged
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
60 changes: 60 additions & 0 deletions pkg/jobs/nic_job_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,66 @@ func NICJobList() []Job {
ch <- jobResult
},
},
{
Name: "exec-agent-conf",
Timeout: time.Second * 10,
Execute: func(dc *data_collector.DataCollector, ctx context.Context, ch chan JobResult) {
jobResult := JobResult{Files: make(map[string][]byte), Error: nil}
command := []string{"cat", "/etc/nginx-agent/nginx-agent.conf"}
for _, namespace := range dc.Namespaces {
pods, err := dc.K8sCoreClientSet.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
dc.Logger.Printf("\tCould not retrieve pod list for namespace %s: %v\n", namespace, err)
} else {
for _, pod := range pods.Items {
if strings.Contains(pod.Name, "ingress") {
for _, container := range pod.Spec.Containers {
res, err := dc.PodExecutor(namespace, pod.Name, container.Name, command, ctx)
if err != nil {
jobResult.Error = err
dc.Logger.Printf("\tCommand execution %s failed for pod %s in namespace %s: %v\n", command, pod.Name, namespace, err)
} else {
fileName := fmt.Sprintf("%s__%s__nginx-agent.conf", pod.Name, container.Name)
jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, fileName)] = res
}
}
}
}
}
}
ch <- jobResult
},
},
{
Name: "exec-agent-version",
Timeout: time.Second * 10,
Execute: func(dc *data_collector.DataCollector, ctx context.Context, ch chan JobResult) {
jobResult := JobResult{Files: make(map[string][]byte), Error: nil}
command := []string{"/usr/bin/nginx-agent", "--version"}
for _, namespace := range dc.Namespaces {
pods, err := dc.K8sCoreClientSet.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
dc.Logger.Printf("\tCould not retrieve pod list for namespace %s: %v\n", namespace, err)
} else {
for _, pod := range pods.Items {
if strings.Contains(pod.Name, "ingress") {
for _, container := range pod.Spec.Containers {
res, err := dc.PodExecutor(namespace, pod.Name, container.Name, command, ctx)
if err != nil {
jobResult.Error = err
dc.Logger.Printf("\tCommand execution %s failed for pod %s in namespace %s: %v\n", command, pod.Name, namespace, err)
} else {
fileName := fmt.Sprintf("%s__%s__nginx-agent-version.txt", pod.Name, container.Name)
jobResult.Files[filepath.Join(dc.BaseDir, "exec", namespace, fileName)] = res
}
}
}
}
}
}
ch <- jobResult
},
},
{
Name: "crd-objects",
Timeout: time.Second * 10,
Expand Down