Skip to content

Commit

Permalink
- add free space display
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Galushko committed Jul 3, 2024
1 parent a432231 commit d3dd030
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,38 @@
public class CheckDiskFreeSpace extends CliCommandExecutor {
@Override
protected String getResultString(List<String> lines, SmartJson rabbitMessage) {
log.debug(String.format("[CheckDiskFreeSpace] [%s]", String.join(", ", lines)));
StringBuilder sb = new StringBuilder("Вільного місця у сховищі:");

for (String line : lines) {
sb.append("\n").append(line);
}
log.debug(String.format("[CheckDiskFreeSpace] df -h result:\n[%s]", String.join("\n", lines)));
log.debug(String.format("[CheckDiskFreeSpace] folders:\n[%s]", String.join("\n", Constants.FOLDERS.keySet())));

StringBuilder sb = new StringBuilder("Вільного місця у сховищі:");
for (val device : Constants.FOLDERS.entrySet()) {
boolean flag = false;
sb.append("\n").append(device.getKey());
boolean storageIsFound = false;
for (String line : lines) {
if (line.matches(device.getKey() + ".*")) {
String size = line;
size = size.replaceAll("^\\S+\\s+\\S+\\s+\\S+\\s+", "");
size = size.replaceAll("\\S+\\s+\\S+\\s*$", "");

sb.append("\n").append(device.getKey());
sb.append(": ").append(size);
sb.append(": ").append(getSize(line));

flag = true;
log.debug(String.format("[CheckDiskFreeSpace] Folder [%s] is present in line [%s]", device.getKey(), line));
storageIsFound = true;
break;
}
log.debug(String.format("[CheckDiskFreeSpace] Folder [%s] is NOT present in line [%s]", device.getKey(), line));
}
if (!flag) {
if (!storageIsFound) {
sb.append("\n").append(device.getKey()).append(": не вказано Filesystem у налаштуваннях");
}
}

return sb.toString();
}

private static String getSize(String line) {
String size = line;
size = size.replaceAll("^\\S+\\s+\\S+\\s+\\S+\\s+", "");
size = size.replaceAll("\\S+\\s+\\S+\\s*$", "");
return size;
}

@Override
protected String getQueue() {
return Queues.File.SHOW_FREE_SPACE;
Expand Down

0 comments on commit d3dd030

Please sign in to comment.