I would like to set a class in cfengine3 so I can perform an action if the disk is almost full.
Asked
Active
Viewed 636 times
2 Answers
3
Here's how I did it. The repair_failed
mnemonic doesn't really fit the "we detected there was less free disk space than you wanted" since it attempts no repair, but it seems to be the way to add a class as a result. It gives a perfectly fine explanation of the free disk space without the extra ohno
class, but eventually I want to clear temp directories, vacuum databases, etc. as a reaction to the condition...
bundle agent storage
{
storage:
"/" volume => low_disk_space;
reports:
ohno::
"Oh noes!";
}
body volume low_disk_space {
freespace => "10%";
repair_failed => { "ohno" };
}

joeforker
- 2,399
- 4
- 26
- 35
-
Indeed, the storage is a better solution than mine. – Nicolas Charles Mar 19 '10 at 20:41
2
You can use the function diskfree that return the available space on the partition
Here is a simple example (yes, I have a lot of free space) :
body common control {
bundlesequence => { "test_free_space" };
}
bundle agent test_free_space {
vars:
"free" int => diskfree("/home");
"min_free_space" int => "200000000";
classes:
"not_enough_size" expression => isgreaterthan("$(min_free_space)", "$(free)");
reports:
not_enough_size::
"There is not enough space left on /home";
}
Regards

Nicolas Charles
- 725
- 5
- 11