Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not asking for password and can't connect to psql #309

Closed
MikaPower opened this issue Jan 26, 2021 · 13 comments
Closed

Not asking for password and can't connect to psql #309

MikaPower opened this issue Jan 26, 2021 · 13 comments
Assignees
Labels

Comments

@MikaPower
Copy link

Hi. I followed this tutorial https://en.admininfo.info/c-mo-instalar-y-configurar-monitorix-en-ubuntu-18
After setting up everything I found that when I go the built-in server it never asks for a password even thought I set it.
I did change enabled = y and also created the password using sudo htpasswd -d -c /var/lib/monitorix/htpasswd admin
Then I tried setting up postgres by enabling the graph and changing the database name, user and password which lead to me having to install DBD::Pg module. After all this I check the logs and it shows:
gsql::pgsql_update: Cannot connect to PostgreSQL 'localhost:5432'.
ERROR: while updating /var/lib/monitorix/pgsql.rrd: /var/lib/monitorix/pgsql.rrd: expected timestamp not found in data source from N

Thanks
Nuno

@mikaku mikaku self-assigned this Jan 26, 2021
@mikaku
Copy link
Owner

mikaku commented Jan 26, 2021

Hi. I followed this tutorial https://en.admininfo.info/c-mo-instalar-y-configurar-monitorix-en-ubuntu-18
After setting up everything I found that when I go the built-in server it never asks for a password even thought I set it.
I did change enabled = y and also created the password using sudo htpasswd -d -c /var/lib/monitorix/htpasswd admin

This is because you forgot to specify which hosts/IPs will be forced to authenticate. By default none is (which looks like not much sense to me right now).

Starting from the 3.13.0 version there are two new options inside the <auth> subsection: hosts_deny and hosts_allow (documented here) which are empty by default, which means that even when authentication is enabled all hosts can pass through. This is intended to have a list of hostnames or IP address that don't need to authenticate because they are trusted.

So, just define the option hosts_deny = all and you'll force authentication to everybody.

I'll modify the main configuration file to include the option hosts_deny = all in order to keep the same behavior as it had before the introduction of this new feature in #274.

Sorry for the inconveniences.

Then I tried setting up postgres by enabling the graph and changing the database name, user and password which lead to me having to install DBD::Pg module. After all this I check the logs and it shows:
gsql::pgsql_update: Cannot connect to PostgreSQL 'localhost:5432'.
ERROR: while updating /var/lib/monitorix/pgsql.rrd: /var/lib/monitorix/pgsql.rrd: expected timestamp not found in data source from N

Please, make sure your PostgreSQL is listening in the port 5432 at localhost.

@MikaPower
Copy link
Author

MikaPower commented Jan 26, 2021

Please, make sure your PostgreSQL is listening in the port 5432 at localhost.

Pgsql is working fine on that port. I even created a script to test it

 #!/usr/bin/perl

use DBI;

my $dbh = DBI->connect('dbi:Pg:dbname=database;','user','pass',{AutoCommit$
print "2+2=",$dbh->selectrow_array("SELECT 2+2"),"\n";

I can also access it on local machine and on the outside if I open port 5432

My pg_hba.conf:

# IPv4 local connections:

host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0               md5
host    all             all             127.0.0.1/32            trust

# IPv6 local connections:
host    all             all             ::1/128                 md5

Is there any place after monitorix log in which I can see more info on the error?
Thanks

@mikaku
Copy link
Owner

mikaku commented Jan 26, 2021

Can you, please, paste the <pgsql> section from your configuration file?

Also, the output of netstat -lntp or ss -lntp.
Thanks.

@MikaPower
Copy link
Author

MikaPower commented Jan 26, 2021

So, just define the option hosts_deny = all and you'll force authentication to everybody.

Doing this didn't asks me for authentication, instead got an 403.

Can you, please, paste the section from your configuration file?

<pgsql>
        list = localhost
        <desc>
                <localhost>
                        host = localhost
                        port = 5432
                        username = nuno
                        password = ......
                        db_list = extreme,
                </localhost>
        </desc>
        rigid = 0, 0, 0, 0, 0, 0
        limit = 100, 100, 100, 100, 100, 100
</pgsql>

Also, the output of netstat -lntp or ss -lntp

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      30662/rpcbind       
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      23558/monitorix-htt 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      915/nginx: master p 
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      692/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      894/sshd            
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      14583/postgres      
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      915/nginx: master p 
tcp6       0      0 :::111                  :::*                    LISTEN      30662/rpcbind       
tcp6       0      0 :::22                   :::*                    LISTEN      894/sshd            
tcp6       0      0 :::5432                 :::*                    LISTEN      14583/postgres  
State   Recv-Q   Send-Q      Local Address:Port       Peer Address:Port                                                              
LISTEN  0        128               0.0.0.0:111             0.0.0.0:*       users:(("rpcbind",pid=30662,fd=8))                        
LISTEN  0        128               0.0.0.0:8080            0.0.0.0:*       users:(("monitorix-httpd",pid=23601,fd=3))                
LISTEN  0        128               0.0.0.0:80              0.0.0.0:*       users:(("nginx",pid=27257,fd=9),("nginx",pid=915,fd=9))   
LISTEN  0        128         127.0.0.53%lo:53              0.0.0.0:*       users:(("systemd-resolve",pid=692,fd=13))                 
LISTEN  0        128               0.0.0.0:22              0.0.0.0:*       users:(("sshd",pid=894,fd=3))                             
LISTEN  0        128               0.0.0.0:5432            0.0.0.0:*       users:(("postgres",pid=14583,fd=7))                       
LISTEN  0        128               0.0.0.0:443             0.0.0.0:*       users:(("nginx",pid=27257,fd=8),("nginx",pid=915,fd=8))   
LISTEN  0        128                  [::]:111                [::]:*       users:(("rpcbind",pid=30662,fd=11))                       
LISTEN  0        128                  [::]:22                 [::]:*       users:(("sshd",pid=894,fd=4))                             
LISTEN  0        128                  [::]:5432               [::]:*       users:(("postgres",pid=14583,fd=8)) 

I also tried giving a wrong password but it didn't give any extra info besides the error on my first post

@mikaku
Copy link
Owner

mikaku commented Jan 26, 2021

Doing this didn't asked me authentication, instead got an 403.

You must declare that option inside the <auth> subsection. I've checked and it works.

I also tried giving a wrong password but it didn't give any extra info besides the error on my first post

You might want to add the -d pgsql or even -d all argument when running Monitorix to get more debug information.

@MikaPower
Copy link
Author

You must declare that option inside the subsection. I've checked and it works.

Ah men, my bad, sorry making you lose time on this one.

You might want to add the -d pgsql or even -d all argument when running Monitorix to get more debug information.

Which command should I add this?
I start monitorix with systemctl start monitorix

@mikaku
Copy link
Owner

mikaku commented Jan 26, 2021

Which command should I add this?
I start monitorix with systemctl start monitorix

Monitorix, as many other tools, have an environment file located in /etc/sysconfig/monitorix from which you can add extra command line options that will be passed when Monitorix is started.

You must configure it like this:

# Here you can specify your Monitorix command line options.
#
OPTIONS="-d pgsql"

@MikaPower
Copy link
Author

Still the same info as before. I'm checking the file /var/log/monotorix. Is this the right file?

@mikaku
Copy link
Owner

mikaku commented Jan 26, 2021

Still the same info as before. I'm checking the file /var/log/monotorix. Is this the right file?

You should get much more information in /var/log/monitorix.
What OS you have there? and how do you installed Monitorix?

@MikaPower
Copy link
Author

MikaPower commented Jan 26, 2021

You should get much more information in /var/log/monitorix

Looks the same as before

What OS you have there? and how do you installed Monitorix?

Ubuntu 18.04, and I installed monitorix following the tutorial on my first post

I partially solved the problem. In the file pgsql.rm line 207
"DBI:Pg:host=$host;port=$port",
I added the database name:
"dbi:Pg:dbname=extreme;host=$host;port=$port",
The graphs are now working, I didn't check where you iterate the databases list on the pgsql conf options but I will do it now and see if I can help a little more.

@mikaku
Copy link
Owner

mikaku commented Jan 26, 2021

I added the database name:

The PostgreSQL module was added in this 3.13.0 version, perhaps it needs some fixings, but it worked finely here.
You shouldn't have to add the database name in there because Monitorix first takes the global parameters and then the specific database parameters.

I think that the user you configured only have permission for the extreme database and not for the global configuration.

Hmm, I see an extra comma at the end of your database name in the option db_list.

                        db_list = extreme,

This should be harmless, but it's better to not be there.

@MikaPower
Copy link
Author

You are indeed correct. On the pgsql config file I used the database owner and not the postgres user.
After using postgres user everything works fine.
I would like to thank you for your time and work.
Have a nice day.

mikaku added a commit that referenced this issue Jan 27, 2021
…built-in server to bypass Basic Authentication when the option 'hosts_deny' is not defined #309
@mikaku mikaku added the bug label Jan 27, 2021
@mikaku
Copy link
Owner

mikaku commented Jan 27, 2021

Many thanks for reporting that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants