Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8662595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:46:17+00:00 2026-06-12T16:46:17+00:00

I am setting up a new Nagios install using OMD & check_mk instead of

  • 0

I am setting up a new Nagios install using OMD & check_mk instead of doing everything by hand this time. The switches do not have proper hostnames in DNS so check_mk provides a method to specify the IP in the config file. I was converting the configuration file for some switches last night and I tried for a few minutes to do it one shot but then threw in the towel.

Example input:

define host{
    use         generic-switch
    host_name   BAR.MDF.MODEL
    alias       BAR.MDF.MODEL
    parents     FOO.MDF.MODEL.01
    address     10.1.1.1
    }

Required output:

ipaddresses = {
  "BAR.MDF.MODEL" : "10.1.1.1",
}

Here is what I did.

I knew that IPs were always after host_name so it is fairly safe/consistent

{ awk '/host_name/ || /address/ { print $2 }' < switch.cfg; } >> out.txt

which got me

BAR.MDF.MODEL
10.1.1.1

Then I did this

{ awk '!/^1/{ getline ip; print $0, ip; next }' < out.txt; } >> out2.txt

to get this:

BAR.MDF.MODEL 10.1.1.1

the rest of the formating was done in vim via ‘norm’ & macros etc

  "BAR.MDF.MODEL" : "10.1.1.1",
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:46:18+00:00Added an answer on June 12, 2026 at 4:46 pm

    Try if this could work for you. Only awk.

    Assuming following data of infile

    define host{
        use         generic-switch
        host_name   BAR.MDF.MODEL
        alias       BAR.MDF.MODEL
        parents     FOO.MDF.MODEL.01
        address     10.1.1.1
        }
    define host{
        use         generic-switch
        host_name   BAR.MDF.MODEL.2
        alias       BAR.MDF.MODEL
        parents     FOO.MDF.MODEL.01
        address     10.1.1.2
        }
    define host{
        use         generic-switch
        host_name   BAR.MDF.MODEL.3
        alias       BAR.MDF.MODEL
        parents     FOO.MDF.MODEL.01
        address     10.1.1.3
        }
    

    Run this awk script:

    awk '
        BEGIN { print "ipaddresses = {"; } 
        $1 == "host_name" { 
            hostname = "\"" $2 "\""; 
            next; 
        } 
        $1 == "address" { 
            address = "\"" $2 "\"";
            printf "\t%s : %s,\n", hostname, address;
        } 
        END {
            printf "}\n";
        }
    ' switch.cfg
    

    That yields:

    ipaddresses = {
            "BAR.MDF.MODEL" : "10.1.1.1",
            "BAR.MDF.MODEL.2" : "10.1.1.2",
            "BAR.MDF.MODEL.3" : "10.1.1.3",
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am generating the scala AST using the following code: val setting = new
Java newbie here, I'm having trouble setting a new line in this code: String
I'm setting a new stack of ViewControllers to my navigationController by doing the following:
This my code for setting new cookie Cookie citizen = new Cookie(citizen,email); citizen.setMaxAge(3600); response.addCookie(citizen);
Setting up new git installations. On one Windows laptop, I'm running (under cygwin): git
How to view all the content in my IsolatedStorageFile by setting a new page
I'm setting up a new project and have gotten NHibernate to work with structuremap...sorta.
I am setting up a new jenkins server and am running into a problem.
I'm setting up a new RedHat Enterprise Linux 5 system to host Ruby apps
I'm setting up a new project and I want to choose a license that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.