Bases: PrimaryModel
Record of a single fully-executed Nautobot command.
Incomplete commands (those requiring additional user input) should not be recorded,
nor should any "help" commands or invalid command entries.
Source code in nautobot_chatops/models.py
| class CommandLog(PrimaryModel): # pylint: disable=nb-string-field-blank-null
"""Record of a single fully-executed Nautobot command.
Incomplete commands (those requiring additional user input) should not be recorded,
nor should any "help" commands or invalid command entries.
"""
start_time = models.DateTimeField(null=True)
runtime = models.DurationField(null=True)
user_name = models.CharField(max_length=255, help_text=COMMAND_LOG_USER_NAME_HELP_TEXT)
user_id = models.CharField(max_length=255, help_text=COMMAND_LOG_USER_ID_HELP_TEXT)
platform = models.CharField(max_length=64, help_text=COMMAND_LOG_PLATFORM_HELP_TEXT)
platform_color = ColorField()
command = models.CharField(max_length=64, help_text=COMMAND_LOG_COMMAND_TEXT)
subcommand = models.CharField(max_length=64, help_text=COMMAND_LOG_SUBCOMMAND_HELP_TEXT)
params = models.JSONField(default=list, help_text=COMMAND_LOG_PARAMS_HELP_TEXT)
status = models.CharField(
max_length=32,
choices=CommandStatusChoices,
default=CommandStatusChoices.STATUS_SUCCEEDED,
)
details = models.CharField(max_length=255, default="")
nautobot_user = models.ForeignKey(
to=settings.AUTH_USER_MODEL,
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="command_log",
)
@property
def status_label_class(self):
"""Bootstrap CSS label class for each status value."""
# pylint: disable=no-else-return
if self.status == CommandStatusChoices.STATUS_SUCCEEDED:
return "success"
elif self.status == CommandStatusChoices.STATUS_BLOCKED:
return "default"
elif self.status == CommandStatusChoices.STATUS_FAILED:
return "warning"
else: # STATUS_ERRORED, STATUS_UNKNOWN
return "danger"
def __str__(self):
"""String representation of a CommandLog entry."""
return f"{self.user_name} on {self.platform}: {self.command} {self.subcommand} {self.params} ({self.status})"
def get_absolute_url(self, api=False):
"""Override the objects absolute url since we have no detail view."""
return reverse("plugins:nautobot_chatops:commandlog_list")
class Meta:
"""Meta-attributes of a CommandLog."""
ordering = ["start_time"]
|
status_label_class
property
Bootstrap CSS label class for each status value.
Meta-attributes of a CommandLog.
Source code in nautobot_chatops/models.py
| class Meta:
"""Meta-attributes of a CommandLog."""
ordering = ["start_time"]
|
__str__()
String representation of a CommandLog entry.
Source code in nautobot_chatops/models.py
| def __str__(self):
"""String representation of a CommandLog entry."""
return f"{self.user_name} on {self.platform}: {self.command} {self.subcommand} {self.params} ({self.status})"
|
get_absolute_url(api=False)
Override the objects absolute url since we have no detail view.
Source code in nautobot_chatops/models.py
| def get_absolute_url(self, api=False):
"""Override the objects absolute url since we have no detail view."""
return reverse("plugins:nautobot_chatops:commandlog_list")
|