bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/apache_mod_info_linux_test.go (about) 1 package collectors 2 3 import ( 4 "strings" 5 "testing" 6 7 "golang.org/x/net/html" 8 ) 9 10 const ( 11 apacheModInfoServerHTML = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 12 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 13 <html xmlns="http://www.w3.org/1999/xhtml"> 14 <head> 15 <title>Server Information</title> 16 </head> 17 <body><h1 style="text-align: center">Apache Server Information</h1> 18 <h2><a name="server">Server Settings</a></h2><dl><dt><strong>Server Version:</strong> <font size="+1"><tt>Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3</tt></font></dt> 19 <dt><strong>Server Built:</strong> <font size="+1"><tt>May 13 2013 22:11:16</tt></font></dt> 20 <dt><strong>Server loaded APR Version:</strong> <tt>1.3.9</tt></dt> 21 <dt><strong>Compiled with APR Version:</strong> <tt>1.3.9</tt></dt> 22 <dt><strong>Server loaded APU Version:</strong> <tt>1.3.9</tt></dt> 23 <dt><strong>Compiled with APU Version:</strong> <tt>1.3.9</tt></dt> 24 <dt><strong>Module Magic Number:</strong> <tt>20051115:25</tt></dt> 25 <dt><strong>Hostname/port:</strong> <tt>127.0.0.1:80</tt></dt> 26 <dt><strong>Timeouts:</strong> <tt>connection: 60 keep-alive: 15</tt></dt><dt><strong>MPM Name:</strong> <tt>Prefork</tt></dt> 27 <dt><strong>MPM Information:</strong> <tt>Max Daemons: 64 Threaded: no Forked: yes</tt></dt> 28 <dt><strong>Server Architecture:</strong> <tt>64-bit</tt></dt> 29 <dt><strong>Server Root:</strong> <tt>/etc/httpd</tt></dt> 30 <dt><strong>Config File:</strong> <tt>/etc/httpd/conf/httpd.conf</tt></dt> 31 <dt><strong>Server Built With:</strong> 32 <tt style="white-space: pre;"> 33 -D APACHE_MPM_DIR="server/mpm/prefork" 34 -D APR_HAS_SENDFILE 35 -D APR_HAS_MMAP 36 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) 37 -D APR_USE_SYSVSEM_SERIALIZE 38 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT 39 -D APR_HAS_OTHER_CHILD 40 -D AP_HAVE_RELIABLE_PIPED_LOGS 41 -D HTTPD_ROOT="/etc/httpd" 42 -D SUEXEC_BIN="/usr/sbin/suexec" 43 -D DEFAULT_ERRORLOG="logs/error_log" 44 -D AP_TYPES_CONFIG_FILE="conf/mime.types" 45 -D SERVER_CONFIG_FILE="conf/httpd.conf" 46 </tt></dt> 47 </dl><hr /><address>Apache/2.2.15 (CentOS) Server at 127.0.0.1 Port 80</address> 48 </body></html> 49 ` 50 ) 51 52 func TestApacheModInfoEmpty(t *testing.T) { 53 54 n, err := html.Parse(strings.NewReader("")) 55 if err != nil { 56 t.Errorf("unable to parse ?server status page") 57 } 58 59 c, k, err := extractTimeouts(n) 60 if c != 0 || k != 0 || err == nil { 61 t.Errorf("Expected 0,0,ERROR got %v,%v,%v", c, k, err) 62 } 63 64 mpm_d, mpm_t, mpm_f, err := extractMpmInfo(n) 65 if (mpm_d != 0) || (mpm_t != false) || (mpm_f != false) || (err == nil) { 66 t.Errorf("Expected 0,false,false,<nil> got %v,%v,%v,%v", mpm_d, mpm_t, mpm_f, err) 67 } 68 69 } 70 71 func TestApacheModInfoServerSimple(t *testing.T) { 72 n, err := html.Parse(strings.NewReader(apacheModInfoServerHTML)) 73 if err != nil { 74 t.Errorf("unable to parse ?server status page") 75 } 76 77 c, k, err := extractTimeouts(n) 78 if c != 60 || k != 15 || err != nil { 79 t.Errorf("Expected 60,15,<nil> got %v,%v,%v", c, k, err) 80 } 81 82 mpm_d, mpm_t, mpm_f, err := extractMpmInfo(n) 83 if (mpm_d != 64) || (mpm_t != false) || (mpm_f != true) || (err != nil) { 84 t.Errorf("Expected 64,false,true,<nil> got %v,%v,%v,%v", mpm_d, mpm_t, mpm_f, err) 85 } 86 87 }