Add computer name to azure sd

Signed-off-by: darshanime <deathbullet@gmail.com>
This commit is contained in:
darshanime 2021-07-25 22:04:32 +05:30
parent 79d354ad2e
commit c8a2ffdb72
3 changed files with 26 additions and 0 deletions

View file

@ -46,6 +46,7 @@ const (
azureLabelMachineID = azureLabel + "machine_id"
azureLabelMachineResourceGroup = azureLabel + "machine_resource_group"
azureLabelMachineName = azureLabel + "machine_name"
azureLabelMachineComputerName = azureLabel + "machine_computer_name"
azureLabelMachineOSType = azureLabel + "machine_os_type"
azureLabelMachineLocation = azureLabel + "machine_location"
azureLabelMachinePrivateIP = azureLabel + "machine_private_ip"
@ -226,6 +227,7 @@ type azureResource struct {
type virtualMachine struct {
ID string
Name string
ComputerName string
Type string
Location string
OsType string
@ -306,6 +308,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
azureLabelTenantID: model.LabelValue(d.cfg.TenantID),
azureLabelMachineID: model.LabelValue(vm.ID),
azureLabelMachineName: model.LabelValue(vm.Name),
azureLabelMachineComputerName: model.LabelValue(vm.ComputerName),
azureLabelMachineOSType: model.LabelValue(vm.OsType),
azureLabelMachineLocation: model.LabelValue(vm.Location),
azureLabelMachineResourceGroup: model.LabelValue(r.ResourceGroup),
@ -463,6 +466,7 @@ func mapFromVM(vm compute.VirtualMachine) virtualMachine {
return virtualMachine{
ID: *(vm.ID),
Name: *(vm.Name),
ComputerName: *(vm.VirtualMachineProperties.OsProfile.ComputerName),
Type: *(vm.Type),
Location: *(vm.Location),
OsType: osType,
@ -490,6 +494,7 @@ func mapFromVMScaleSetVM(vm compute.VirtualMachineScaleSetVM, scaleSetName strin
return virtualMachine{
ID: *(vm.ID),
Name: *(vm.Name),
ComputerName: *(vm.VirtualMachineScaleSetVMProperties.OsProfile.ComputerName),
Type: *(vm.Type),
Location: *(vm.Location),
OsType: osType,

View file

@ -30,10 +30,14 @@ func TestMapFromVMWithEmptyTags(t *testing.T) {
name := "name"
vmType := "type"
location := "westeurope"
computerName := "computer_name"
networkProfile := compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
}
properties := &compute.VirtualMachineProperties{
OsProfile: &compute.OSProfile{
ComputerName: &computerName,
},
StorageProfile: &compute.StorageProfile{
OsDisk: &compute.OSDisk{
OsType: "Linux",
@ -54,6 +58,7 @@ func TestMapFromVMWithEmptyTags(t *testing.T) {
expectedVM := virtualMachine{
ID: id,
Name: name,
ComputerName: computerName,
Type: vmType,
Location: location,
OsType: "Linux",
@ -71,6 +76,7 @@ func TestMapFromVMWithTags(t *testing.T) {
name := "name"
vmType := "type"
location := "westeurope"
computerName := "computer_name"
tags := map[string]*string{
"prometheus": new(string),
}
@ -78,6 +84,9 @@ func TestMapFromVMWithTags(t *testing.T) {
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
}
properties := &compute.VirtualMachineProperties{
OsProfile: &compute.OSProfile{
ComputerName: &computerName,
},
StorageProfile: &compute.StorageProfile{
OsDisk: &compute.OSDisk{
OsType: "Linux",
@ -98,6 +107,7 @@ func TestMapFromVMWithTags(t *testing.T) {
expectedVM := virtualMachine{
ID: id,
Name: name,
ComputerName: computerName,
Type: vmType,
Location: location,
OsType: "Linux",
@ -115,10 +125,14 @@ func TestMapFromVMScaleSetVMWithEmptyTags(t *testing.T) {
name := "name"
vmType := "type"
location := "westeurope"
computerName := "computer_name"
networkProfile := compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
}
properties := &compute.VirtualMachineScaleSetVMProperties{
OsProfile: &compute.OSProfile{
ComputerName: &computerName,
},
StorageProfile: &compute.StorageProfile{
OsDisk: &compute.OSDisk{
OsType: "Linux",
@ -140,6 +154,7 @@ func TestMapFromVMScaleSetVMWithEmptyTags(t *testing.T) {
expectedVM := virtualMachine{
ID: id,
Name: name,
ComputerName: computerName,
Type: vmType,
Location: location,
OsType: "Linux",
@ -158,6 +173,7 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
name := "name"
vmType := "type"
location := "westeurope"
computerName := "computer_name"
tags := map[string]*string{
"prometheus": new(string),
}
@ -165,6 +181,9 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
}
properties := &compute.VirtualMachineScaleSetVMProperties{
OsProfile: &compute.OSProfile{
ComputerName: &computerName,
},
StorageProfile: &compute.StorageProfile{
OsDisk: &compute.OSDisk{
OsType: "Linux",
@ -186,6 +205,7 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
expectedVM := virtualMachine{
ID: id,
Name: name,
ComputerName: computerName,
Type: vmType,
Location: location,
OsType: "Linux",

View file

@ -386,6 +386,7 @@ The following meta labels are available on targets during [relabeling](#relabel_
* `__meta_azure_machine_id`: the machine ID
* `__meta_azure_machine_location`: the location the machine runs in
* `__meta_azure_machine_name`: the machine name
* `__meta_azure_machine_computer_name`: the machine computer name
* `__meta_azure_machine_os_type`: the machine operating system
* `__meta_azure_machine_private_ip`: the machine's private IP
* `__meta_azure_machine_public_ip`: the machine's public IP if it exists