Exemplo n.º 1
0
    def start(self, silent=False):
        if self.is_up():
            return False

        if not self.service_dict.get("privileged", False):
            # run command as regular nav user
            user = NAV_CONFIG.get("NAV_USER", "navcron")
            command = 'su - {user} -c "{command}"'.format(
                command=self._command, user=user)
        else:
            command = self._command

        return self.execute(command, silent=silent)
Exemplo n.º 2
0
    def update_init(self):
        """Update the __init__ block with current environment
        variables and such."""
        time_string = time.strftime("%Y-%m-%d %H:%M:%S",
                                    time.localtime(time.time()))
        env_vars = ('PERL5LIB', 'PYTHONPATH', 'CLASSPATH', 'PATH')
        init_block = ['# NAV updated this crontab at: ' + time_string]
        for var in env_vars:
            if var in os.environ:
                val = os.environ[var]
                init_block.append('%s="%s"' % (var, val))

        # Set up a default MAILTO directive
        mailto = NAV_CONFIG.get('ADMIN_MAIL', 'root@localhost')

        init_block.append('MAILTO=' + mailto)
        if '__init__' not in self:
            # If we don't have an init block, make sure we put it at
            # the very top of the crontab
            self.content[0:0] = ['##block __init__##', '##end##']
            self._parse_blocks()
        self['__init__'] = init_block
Exemplo n.º 3
0
Arquivo: views.py Projeto: yytsui/nav
from django.http import HttpResponseRedirect, HttpResponseForbidden
from django.shortcuts import render

from nav.config import NAV_CONFIG, find_configfile

from nav.django.utils import get_account

from nav.models.logger import LogMessage
from nav.models.logger import ErrorError
from nav.web.syslogger.forms import LoggerGroupSearchForm
from nav.web.utils import create_title

DATEFORMAT = "%Y-%m-%d %H:%M:%S"

try:
    DOMAIN_SUFFICES = NAV_CONFIG.get("DOMAIN_SUFFIX", "").split(",")
except IOError:
    DOMAIN_SUFFICES = []
DOMAIN_SUFFICES = [s.strip() for s in DOMAIN_SUFFICES]

logger = logging.getLogger("nav.web.syslogger")


def _strip_empty_arguments(request):
    """Strips empty arguments and their related operator arguments from the
    QueryDict in request.GET and returns a new, possibly modified QueryDict.

    """
    query = request.GET.copy()

    deletable = (key for key, value in query.items() if not value.strip())
Exemplo n.º 4
0
Arquivo: db.py Projeto: plan1230/nav
import nav
from nav.config import NAV_CONFIG
from nav.metrics.data import get_metric_average
from nav.metrics.errors import GraphiteUnreachableError
from nav.metrics.graphs import get_metric_meta
from nav.metrics.names import escape_metric_name
from nav.metrics.templates import (metric_path_for_interface,
                                   metric_path_for_cpu_load,
                                   metric_path_for_cpu_utilization)
from nav.web.geomap.utils import lazy_dict, subdict, is_nan
from nav.util import chunks

_logger = logging.getLogger(__name__)

_domain_suffix = NAV_CONFIG.get('DOMAIN_SUFFIX')

LAYER_3_QUERY = """
    SELECT DISTINCT ON (local_sysname, remote_sysname)
           sysname AS local_sysname,
           ifname AS local_interface,
           netbox.netboxid AS local_netboxid,
           interface_gwport.interfaceid AS local_gwportid,
           interface_gwport.interfaceid AS local_portid,
           NULL AS local_swportid,
           speed AS capacity,
           ifindex,
           conn.*, nettype, netident,
           3 AS layer, NULL AS remote_swportid, vlan.*
    FROM gwportprefix
    JOIN (
Exemplo n.º 5
0
 def __init__(self, filename):
     self.content = None
     if CronService.crontab is None:
         cron_user = NAV_CONFIG.get('NAV_USER', 'navcron')
         CronService.crontab = Crontab(cron_user)
     super(CronService, self).__init__(filename)
Exemplo n.º 6
0
import django
from django.utils.log import DEFAULT_LOGGING

from nav.config import (NAV_CONFIG, getconfig, find_config_dir)
from nav.db import get_connection_parameters
import nav.buildconf

ALLOWED_HOSTS = ['*']

_config_dir = find_config_dir()
try:
    _webfront_config = getconfig('webfront/webfront.conf')
except (IOError, OSError):
    _webfront_config = {}

DEBUG = NAV_CONFIG.get('DJANGO_DEBUG',
                       'False').upper() in ('TRUE', 'YES', 'ON')

# Copy Django's default logging config, but modify it to enable HTML e-mail
# part for improved debugging:
LOGGING = copy.deepcopy(DEFAULT_LOGGING)
_handlers = LOGGING.get('handlers', {})
_mail_admin_handler = _handlers.get('mail_admins', {})
_mail_admin_handler['include_html'] = True

# Admins
ADMINS = (('NAV Administrator', NAV_CONFIG.get('ADMIN_MAIL',
                                               'root@localhost')), )
MANAGERS = ADMINS

# Database / ORM configuration
try:
Exemplo n.º 7
0
def get_search_path():
    """Returns the configured smidumps search path"""
    return NAV_CONFIG.get("SMIDUMPS", "nav.smidumps").split(':')