aboutsummaryrefslogtreecommitdiff
path: root/handlers/sys
blob: ce9c5b03e2d523f267d950dc2186078c9e60aacf (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
#
# this handler will save various reports of vital system information.
# by default, all the reports are enabled and are saved in /var/backups.
#
# (1) a list of all the packages installed and removed.
#     this file can be used to restore the state of installed packages
#     by running "dpkg --set-selections < dpkg-selections.txt
# 
# (2) the partition table of all disks. 
#     this partition table can be used to format another disk of
#     the same size. this can be handy if using software raid and 
#     you have a disk go bad. just replace the disk and partition it
#     by running "sfdisk /dev/sdb < partitions.sdb.txt"
#     (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
#
# (3) hardware information. 
#     write to a text file the important things which hwinfo can gleen.
#

if [ -f /etc/debian_version ]
then
   os=debian
   debug "Debian detected"
   osversion="/etc/debian_version"
elif [ -f /etc/redhat-release ]
then
   os=redhat
   debug "Redhat detected"
   osversion="/etc/redhat-release"
else
   warning "Unknown OS detected!"
fi

getconf packages yes
if [ $os = "debian" ]
then
   getconf packagesfile /var/backups/dpkg-selections.txt
   getconf packagemgr   `which dpkg`
   getconf packagemgroptions ' --get-selections *'
elif [ $os = "redhat" ]
then
   getconf packagesfile  /var/backups/rpmpackages.txt 
   getconf packagemgr	`which rpm`
   getconf packagemgroptions	' -qa '

   getconf SYSREPORT `which sysreport`
   getconf sysreport_options ' -norpm '
else
   getconf packagesfile /var/backups/unknownOS.txt
fi
packagemgroptions="${packagemgroptions//__star__/*}"

getconf partitions yes
getconf partitionsfile /var/backups/partitions.__star__.txt

getconf hardware yes
getconf hardwarefile /var/backups/hardware.txt

getconf sysreport yes
getconf sysreportfile /var/backups/sysreport.txt

getconf SFDISK `which sfdisk`
getconf HWINFO `which hwinfo`
getconf sfdisk_options ""
getconf hwinfo_options ""

# See if vservers are configured
local usevserver=no
if [ $vservers_are_available = yes ]
then
   info "vserver method enabled"
   usevserver=yes
fi

## PACKAGES ##############################

#
# here we grab a list of the packages installed and removed.
#

if [ "$packages" == "yes" ]; then

   if [ $usevserver = yes ]; then
      info "vserver root directory set to: $VROOTDIR"
      for vserver in $found_vservers; do
         info "examining vserver: $vserver"
         # is it running ?
         $VSERVERINFO -q $vserver RUNNING
         if [ $? -ne 0 ]; then
            warning "The vserver $vserver is not running."
            continue
         fi
         # is $packagemgr available inside $vserver ?
         if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
            warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
            continue
         fi
         # don't expand * since it can be used in $packagemgroptions
         set -o noglob
	 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
	 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
         set +o noglob
      done
   fi
   
   # We want to perform this on the host as well
   if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then 
      warning "can't find ${packagemgr}, skipping installed packages report."
   else
      # don't expand * since it can be used in $packagemgroptions
      set -o noglob
      debug "$packagemgr $packagemgroptions > $packagesfile"
      $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
      set +o noglob
   fi

fi

## System report ##############################

#
# here we grab a bunch of system stuff for a report
#

export STATUS

HASHES="#################################################################"
DASHES="-----------------------------------------------------------------"

cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"


catiffile () {
   echo $HASHES >> $sysreportfile
   echo "# $STATUS" >> $sysreportfile
   echo $HASHES >> $sysreportfile
   if [ -f $1 ]; then
      echo "file: $1" >> $sysreportfile
      echo $DASHES >> $sysreportfile
      cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
   fi
   if [ -d $1 ]; then
      echo "directory: $1" >> $sysreportfile
      echo $DASHES >> $sysreportfile
      for file in `find $1 -maxdepth 3 -noleaf -type f`
      do
       catiffile $file
      done
   fi
   echo $DASHES >> $sysreportfile
} 

catifexec () {
   echo $HASHES >> $sysreportfile
   echo "# $STATUS" >> $sysreportfile
   echo $HASHES >> $sysreportfile
   $1  >> $sysreportfile 2>&1 || info "executing of $1 failed"
}
   

STATUS="Determining $os version:"
catiffile $osversion

STATUS="Determinding your current hostname: " 
catifexec "/bin/hostname"

STATUS="Getting the date:"
catifexec "/bin/date"

STATUS="Checking your systems current uptime and load average:"
catifexec "/usr/bin/uptime"

STATUS="Checking available memory:"
catifexec "/usr/bin/free"

STATUS="Checking free disk space:"
catifexec "/bin/df" "-al"

STATUS="Collecting what services run at what run level:"
if [ $os = "redhat" ]; then
   catifexec "/sbin/chkconfig --list"
   STATUS="Collecting information about /etc/rc.d:"
   catiffile "/bin/ls /etc/rc.d/rc*.d/"

elif [ $os = "debian" ]; then
    for level in 0 1 2 3 4 5 6 S; do
       echo "Level: $level" >> $sysreportfile
       for f in /etc/rc${level}.d/*; do
	# Remove /etc/Knn or Snn from beginning
          ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
          if [ $f != $ff ]; then
             echo $ff >> $sysreportfile
          fi
       done
       echo "" >> $sysreportfile
    done
fi

STATUS="Getting bootloader information:"
catifexec "/bin/ls -alR /boot"

# This covers sparc, alpha, and intel (respectively)
# updated for grub -mpg
if [ -f /etc/silo.conf ]; then
  STATUS="Collecting information about the boot process (silo):"
  catiffile "/etc/silo.conf"
fi
if [ -f /etc/milo.conf ]; then
  STATUS="Collecting information about the boot process (milo):"
  catiffile "/etc/milo.conf"
fi
if [ -f /etc/lilo.conf ]; then
  STATUS="Collecting information about the boot process (lilo):"
  catiffile "/etc/lilo.conf"
  catifexec "/sbin/lilo -q"
fi
if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
  STATUS="Collecting information about the boot process (grub.conf):"
  catiffile "/boot/grub/grub.conf"
  STATUS="Collecting information about the boot process (grub.map):"
  catiffile "/boot/grub/device.map"
fi
if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
  STATUS="Gathering information on cluster setup"
  # 2.1 AS
  if [ -f /etc/cluster.conf ] ; then
    catiffile "/etc/cluster.conf"
  fi
  # Taroon
  if [ -f /etc/cluster.xml ] ; then
    catiffile "/etc/cluster.xml"
  fi
fi

STATUS="Gathering sysctl information (sysctl -a):"
catiffile "sysctl -a 2>/dev/null"
STATUS="Gathering sysctl information (/etc/sysctl.conf):"
catiffile "/etc/sysctl.conf"

STATUS="Gathering IP information (/sbin/ifconfig):"
catifexec "/sbin/ifconfig -a"

STATUS="Gathering additional IP information (/bin/ip addr list):"
catifexec "/bin/ip addr list"

STATUS="Checking network routes:"
catifexec "/sbin/route -n"

STATUS="Collecting Name Service Switch config information:"
catiffile "/etc/nsswitch.conf"

STATUS="Collecting information about system authentication (pam):"
catiffile "/etc/pam.conf"
catiffile "/etc/pam.d"

echo
echo "Getting information about the kernel."
echo
STATUS="Getting kernel version:"
catifexec "/bin/uname" "-a"
STATUS="Checking module information:"
catifexec "/sbin/lsmod"
for x  in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null 
) ; do
  STATUS="Checking module information $x:"
  catifexec "/sbin/modinfo  $x"
done

STATUS="Currently getting ksysms information:"
catifexec "/sbin/ksyms"

STATUS="Gathering information about your filesystems:"
catiffile "/proc/filesystems"

STATUS="Gathering information about your system stat:"
catiffile "/proc/stat"

STATUS="Gathering information about your partitions:"
catiffile "/proc/partitions"

STATUS="Gathering information about your ksyms:"
catiffile "/proc/ksyms"

STATUS="Gathering information about slabinfo:"
catiffile "/proc/slabinfo"

# Added support to cover for the new modules.conf layout in Red Hat 7
STATUS="Collecting information regarding kernel modules"
VER=`uname -r`
catiffile "/lib/modules/$VER/modules.dep"
if [ -f /etc/conf.modules ]; then
  STATUS="Collecting information regarding kernel modules (conf.modules)"
  catiffile "/etc/conf.modules"
fi
if [ -f /etc/modules.conf ]; then
  STATUS="Collecting information regarding kernel modules (modules.conf)"
  catiffile "/etc/modules.conf"
fi
if [ -f /etc/modprobe.conf ]; then
  STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
  catiffile "/etc/modprobe.conf"
fi

# dkms status
if [ -x /usr/sbin/dkms ] ; then
   STATUS="Gathering current status of modules, versions and kernels (dkms):"
  catifexec "/usr/sbin/dkms" "status"
fi

if [ -f /etc/sysconfig/isdncard ] ; then
  STATUS="Gathering information about ISDN:"
  catiffile "/etc/sysconfig/isdncard"
fi

STATUS="Collecting information from the proc directory:"
catiffile "/proc/pci"

STATUS="Getting kernel command line"
catiffile "/proc/cmdline"

STATUS="Gathering information about your CPU:"
catiffile "/proc/cpuinfo"

STATUS="Gathering information about your Ram:"
catiffile "/proc/meminfo"

STATUS="Gathering information about your ioports:"
catiffile "/proc/ioports"

STATUS="Gathering information about your interrupts:"
catiffile "/proc/interrupts"

STATUS="Gathering information about your scsi devices:"
catiffile "/proc/scsi"

STATUS="Gathering information about your dma:"
catiffile "/proc/dma"

STATUS="Gathering information about your devices (/proc/devices):"
catiffile "/proc/devices"

STATUS="Gathering information about your rtc:"
catiffile "/proc/rtc"

STATUS="Gathering information about your ide drivers:"
catiffile "/proc/ide"

STATUS="Gathering information about your bus:"
catifexec lspci
catiffile "/proc/bus"

echo
echo "Getting disk and filesystem information."
echo

STATUS="Collecting information from /etc/fstab:"
catiffile "/etc/fstab"

STATUS="Collecting disk partition information:"
catifexec "fdisk -l"

STATUS="Checking mounted file systems (mount) "
catifexec "/bin/mount"

STATUS="Checking mounted file systems (/proc/mounts)"
catiffile "/proc/mounts"

STATUS="Collecting Software RAID information (/proc/mdstat)"
catiffile "/proc/mdstat"

STATUS="Collecting Software RAID information (/etc/raidtab)"
catiffile "/etc/raidtab"

STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
catiffile "/etc/mdadm.conf"

STATUS="Collecting Automount information (auto.master)"
catiffile "/etc/auto.master"

STATUS="Collecting Automount information (auto.misc)"
catiffile "/etc/auto.misc"

STATUS="Collecting Automount information (auto.net)"
catiffile "/etc/auto.net"

STATUS="Collecting LVM information:"
if [ $os = "redhat" ]; then
   catifexec "/usr/sbin/vgdisplay" "-vv"
elif [ $os = "debian" ]; then
   catifexec "/sbin/vgdisplay" "-vv"
fi
   
STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
catiffile "/etc/stinit.def"

if [ -x /sbin/lsusb ] ; then
  STATUS="Collecting USB devices list (lsusb):"
  catifexec "/sbin/lsusb"
fi

if [ -x /usr/bin/lshal ] ; then
  STATUS="Collecting global devices list (lshal):"
  catifexec "/usr/bin/lshal"
fi


STATUS="Gathering information on SELinux setup"
catifexec "/usr/bin/selinuxconfig"
catifexec "/usr/sbin/sestatus"
if [ $os = "redhat" ]; then
   catifexec "rpm" "-q -V selinux-policy-targeted"
   catifexec "rpm" "-q -V selinux-policy-strict"
fi

if [ $usevserver = yes ]; then
   STATUS="Gathering vserver information"
   catiffile "/proc/virtual"
fi

if [ "$partitions" == "yes" ]; then
	if [ ! -x "$SFDISK" ]; then
		warning "can't find sfdisk, skipping sfdisk report."
		partitions="no"
	fi
	if [ ! -x "$HWINFO" ]; then
		warning "can't find hwinfo, skipping partition report."
		partitions="no"
	fi
fi

if [ "$hardware" == "yes" ]; then
	if [ ! -x "$HWINFO" ]; then
		warning "can't find hwinfo, skipping hardware report."
		hardware="no"
	fi
fi


## PARTITIONS #############################

# here we use sfdisk to dump a listing of all the partitions. 
# these files can be used to directly partition a disk of the same size.

if [ "$partitions" == "yes" ]; then
	devices=`$SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
	if [ "$devices" == "" ]; then 
	   warning "No harddisks found" 
	fi
	for dev in $devices; do
                debug "$SFDISK will try to backup partition tables for device $dev"
		[ -b $dev ] || continue
		label=${dev#/dev/}
		label=${label//\//-}
		outputfile=${partitionsfile//__star__/$label}
		debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
		$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
                if [ $? -ne 0 ]; then
                   warning "The partition table for $dev could not be saved."
                fi
	done
fi

## HARDWARE #############################

#
# here we use hwinfo to dump a table listing all the
# information we can find on the hardware of this machine
# 

if [ "$hardware" == "yes" ]; then
	if [ -f $hardwarefile ]; then
		rm $hardwarefile
	fi
	touch $hardwarefile
	echo -e "\n\n====================== summary ======================\n" >>  $hardwarefile
	debug "$HWINFO --short --cpu --network --disk --pci  >> $hardwarefile"
	$HWINFO --short --cpu --network --disk --pci  >> $hardwarefile
	for flag in cpu network disk bios pci; do
		echo -e "\n\n====================== $flag ======================\n" >>  $hardwarefile
		$HWINFO --$flag >> $hardwarefile
	done
fi