File: linux.cf

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (99 lines) | stat: -rw-r--r-- 4,293 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
bundle common inventory_linux
# @brief Linux inventory
#
# This common bundle is for Linux inventory work.
#
# Provides:
#  systemd class based on linktarget of /proc/1/cmdline
{
  vars:
    have_proc_device_tree::
      "_model_path" string => "/proc/device-tree/model";
      "proc_device_tree_model" string => readfile("$(_model_path)"),
        if => fileexists("$(_model_path)"),
        comment => "Read model from $(_model_path) because it's not available from DMI",
        meta => { "inventory", "attribute_name=System version" };

      "_serial_number_path" string => "/proc/device-tree/serial-number";
      "proc_device_tree_serial_number" string => readfile("$(_serial_number_path)"),
        if => fileexists("$(_serial_number_path)"),
        comment => "Read serial number from $(_serial_number_path) because it's not available from DMI",
        meta => { "inventory", "attribute_name=System serial number" };


    has_proc_1_cmdline::
      "proc_1_cmdline_split" slist => string_split(readfile("/proc/1/cmdline", "512"), " ", "2"),
      comment => "Read /proc/1/cmdline and split off arguments";

      "proc_1_cmdline" string => nth("proc_1_cmdline_split", 0),
      comment => "Get argv[0] of /proc/1/cmdline";

      # this is the same as the original file for non-links
      "proc_1_process" string => filestat($(proc_1_cmdline), "linktarget");

    any::
      "proc_routes" data => data_readstringarrayidx("/proc/net/route",
                                                    "#[^\n]*","\s+",40,4k),
        if => fileexists("/proc/net/route");
      "routeidx" slist => getindices("proc_routes");
      "dgw_ipv4_iface" string => "$(proc_routes[$(routeidx)][0])",
        comment => "Name of the interface where default gateway is routed",
        if => strcmp("$(proc_routes[$(routeidx)][1])", "00000000");

    linux::
      "nfs_servers" -> { "CFE-3259" }
        comment => "NFS servers (to list hosts impacted by NFS outages)",
        slist => maplist( regex_replace( $(this) , ":.*", "", "g"),
                          # NFS server is before the colon (:), that's all we want
                          # e.g., nfs.example.com:/vol/homedir/user1 /home/user1 ...
                          #       ^^^^^^^^^^^^^^^
                          grep( ".* nfs .*",
                                readstringlist("/proc/mounts", "", "\n", inf, inf)
                              )
                        ),
        if => fileexists( "/proc/mounts" );


        "nfs_server[$(nfs_servers)]"
          string => "$(nfs_servers)",
          meta => { "inventory", "attribute_name=NFS Server" };


  classes:

    any::
      "has_proc_1_cmdline" expression => fileexists("/proc/1/cmdline"),
      comment => "Check if we can read /proc/1/cmdline";

      "inventory_have_python_symlink" expression => fileexists("$(sys.bindir)/cfengine-selected-python");

    has_proc_1_cmdline::
      "systemd" expression => strcmp(lastnode($(proc_1_process), "/"), "systemd"),
      comment => "Check if (the link target of) /proc/1/cmdline is systemd";

    inventory_have_python_symlink::
      "cfe_python_for_package_modules_supported" -> { "CFE-2602", "CFE-3512", "ENT-10248" }
        comment => concat( "Here we see if the version of python found is",
                           " acceptable ( 3.x or 2.4 or greater ) for package",
                           " modules. We use this guard to prevent errors",
                           " related to missing python modules."),
        expression => returnszero("$(sys.bindir)/cfengine-selected-python -V 2>&1 | grep ^Python | cut -d' ' -f 2 | ( IFS=. read v1 v2 v3 ; [ $v1 -ge 3 ] || [ $v1 -eq 2 -a $v2 -ge 4 ] )",
                                  useshell);
}

bundle monitor measure_entropy_available
# @brief Measure amount of entropy available
{
  measurements:
    linux::
      # A lack of entropy can cause agents to hang
      "/proc/sys/kernel/random/entropy_avail" -> { "ENT-6495", "ENT-6494" }
        if => fileexists( "/proc/sys/kernel/random/entropy_avail" ),
        handle => "entropy_avail",
        stream_type => "file",
        data_type => "int",
        units => "bits",
        history_type => "weekly",
        match_value => single_value("\d+"),
        comment => "Amount of entropy available";
}