YAML

From Teknologisk videncenter
Revision as of 17:13, 22 March 2025 by Heth (talk | contribs) (examples)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Structure

Block and flow style

Block style

Lists:

fruits:
  - apple
  - banana
  - orange

Maps/dictionary:

address:
  street: "H.C. Andersens vej 9"
  city: Viborg
  zip: 8800

Flow style

Lists:

fruits: [apple, banana, orange]

Maps:/dictionary:

address: {street: "H.C. Andersens vej 9",  city: Viborg,  zip: 8800 }

Data types

Scalars

  • Strings
    • text1: "This is a string"
    • text2: 'This is also a string'
    • text3: This is a string too
    • text4: "2999"
    • text5: | #Multiline string - Preserve new line chars
 Line1
 Line2
    • text6: > #Multiline string - Convert new line to space
 Line1
 Line2
  • Numbers
    • 2999
    • 2e+10
  • Booleans
    • true
    • false
  • Dates
    • "2025-01-01" # ISO-8601 standard
  • Null
    • Name: null
    • Name: ~
    • Name:

examples

db_connect:
  host: "127.0.0.1"
  user: "USERNAME"
  password: "PASSWORD"
  port: "3306"
  database: "nmsdb"

db_create:
# Equipment - devices under network management
  equipment: >
    CREATE TABLE `equipment` (
        `host_id`           INT NOT NULL AUTO_INCREMENT,
        `hostname`              VARCHAR(128) DEFAULT NULL,
        `name`                  VARCHAR(128) DEFAULT NULL,
        `date_created`          TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        `community`             VARCHAR(128) DEFAULT NULL,
        `snmp_ver`              TINYINT DEFAULT NULL,
        `periodic`              INT DEFAULT NULL,
        PRIMARY KEY (`host_id`),
        UNIQUE(`hostname`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
  oids: >
    CREATE TABLE `oids` (
        `oid_id`                INT NOT NULL AUTO_INCREMENT,
        `oid`                   VARCHAR(256),
        `easyname`              VARCHAR(64),
        `description`           VARCHAR(512),
         PRIMARY KEY (`oid_id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;


# Consider change oid in oids to oid basenames and use oid_instance as last digit(s) - unless Null
  probes: >
    CREATE TABLE `probes` (
        `probe_id`              INT NOT NULL AUTO_INCREMENT,
        `host_id`               INT NOT NULL,
        `oid_id`                INT NOT NULL,
        PRIMARY KEY (`probe_id`),
        CONSTRAINT `fk_oid_id` FOREIGN KEY (`oid_id`) REFERENCES `oids` (`oid_id`),
        CONSTRAINT `fk_host_id` FOREIGN KEY (`host_id`) REFERENCES `equipment` (`host_id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

# Only numeric data allowed in this version
  probe_data: >
    CREATE TABLE `probe_data` (
        `probe_data_id` INT NOT NULL AUTO_INCREMENT,
        `probe_id`         INT NOT NULL,
        `timestamp`     BIGINT NOT NULL,
        `value`         BIGINT NOT NULL,
        PRIMARY KEY (`probe_data_id`),
        CONSTRAINT `fk_probe_id` FOREIGN KEY (`probe_id`) REFERENCES `probes` (`probe_id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

testdata:
  - >
      INSERT INTO equipment (hostname, name, community, snmp_ver, periodic)
      VALUES ('192.168.1.64','SW1', 'public', '2', '60');
  - INSERT INTO oids (oid,easyname) VALUES ('1.3.6.1.2.1.2.2.1.10.10005','ifInOctets');
  - INSERT INTO oids (oid,easyname) VALUES ('1.3.6.1.2.1.31.1.1.1.6.10005','ifHCInOctets');
  - INSERT INTO oids (oid,easyname) VALUES ('1.3.6.1.2.1.2.2.1.16.10005','ifOutOctets');
  - INSERT INTO oids (oid,easyname) VALUES ('1.3.6.1.2.1.31.1.1.1.10.10005','ifHCOutOctets');
  - INSERT INTO probes (oid_id,host_id) VALUES (1,1)
  - INSERT INTO probes (oid_id,host_id) VALUES (2,1)
  - INSERT INTO probes (oid_id,host_id) VALUES (3,1)
  - INSERT INTO probes (oid_id,host_id) VALUES (4,1)
  - >
    INSERT INTO equipment (hostname, name, community, snmp_ver, periodic)
    VALUES ('192.168.1.46','SW2', 'public', '2', '60');
  - INSERT INTO oids (oid,easyname) VALUES ('1.3.6.1.2.1.2.2.1.10.4','ifInOctets');
  - INSERT INTO oids (oid,easyname) VALUES ('1.3.6.1.2.1.31.1.1.1.6.4','ifHCInOctets');
  - INSERT INTO oids (oid,easyname) VALUES ('1.3.6.1.2.1.2.2.1.16.4','ifOutOctets');
  - INSERT INTO oids (oid,easyname) VALUES ('1.3.6.1.2.1.31.1.1.1.10.4','ifHCOutOctets');
  - INSERT INTO probes (oid_id,host_id) VALUES (5,2)
  - INSERT INTO probes (oid_id,host_id) VALUES (6,2)
  - INSERT INTO probes (oid_id,host_id) VALUES (7,2)
  - INSERT INTO probes (oid_id,host_id) VALUES (8,2)